安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
cancelAnimationFrame()
方法在
XRSession
interface cancels an animation frame which was previously requested by calling
requestAnimationFrame
.
xrSession.cancelAnimationFrame(handle);
handle
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. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
XRSession
cancelAnimationFrame()
end()
requestAnimationFrame()
requestReferenceSpace()
updateRenderState()