XRSession.cancelAnimationFrame() - Web APIs 编辑
Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The cancelAnimationFrame()
method of the XRSession
interface cancels an animation frame which was previously requested by calling requestAnimationFrame
.
Syntax
xrSession.cancelAnimationFrame(handle);
Parameters
handle
- The unique value returned by the call to
requestAnimationFrame()
that previously scheduled the animation callback.
Return value
None.
Usage notes
This function has no effect if the specified handle
cannot be found.
Example
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()
.
The 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;
}
}
Specifications
Specification | Status | Comment |
---|---|---|
WebXR Device API The definition of 'XRSession.cancelAnimationFrame' in that specification. | Working Draft | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论