安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

cancelAnimationFrame() 方法在 XRSession interface cancels an animation frame which was previously requested by calling requestAnimationFrame .

句法

xrSession.cancelAnimationFrame(handle);
					

参数

handle
The unique value returned by the call to requestAnimationFrame() that previously scheduled the animation callback.

返回值

None.

用法注意事项

This function has no effect if the specified handle cannot be found.

范例

In the example below we see code which starts up a WebXR session if immersive VR mode is supported. Once started, the session schedules its first frame to be rendered by calling requestAnimationFrame() .

pauseXR() function shown at the bottom can be called to suspend the WebVR session, in essence, by canceling any pending animation frame callback. Since each frame callback schedules the next one, removing the callback terminates updating of the WebXR scene.

const XR = navigator.xr;
let requestHandle = null;
let xrSession = null;
if (XR) {
  XR.isSessionSupported('immersive-vr')
  .then((isSupported) => {
    if (isSupported) {
      startXR();
    }
  });
}
function frameCallback(time, xrFrame) {
  xrSession.requestAnimationFrame(frameCallback);
  // Update and render the frame
}
async function startXR() {
  xrSession = XR.requestSession("immersive-vr");
  if (xrSession) {
    stopButton.onclick = stopXR;
    requestHandle = xrSession.requestAnimationFrame(frameCallback);
  }
}
function pauseXR() {
  if (xrSession && requestHandle) {
    xrSession.cancelAnimationFrame(requestHandle);
    requestHandle = null;
  }
}
					

规范

规范 状态 注释
WebXR 设备 API
The definition of 'XRSession.cancelAnimationFrame' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
cancelAnimationFrame() Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: