安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
visibilitychange
event is sent to an
XRSession
to inform it when it becomes visible or hidden, or when it becomes visible but not currently focused.
Upon receiving the event, you can check the value of the session's
visibilityState
property to determine the new visibility state.
| 冒泡 | Yes |
|---|---|
| 可取消 | No |
| 接口 |
XRSessionEvent
|
| 事件处理程序特性 |
onvisibilitychange
|
当
XRSession
receives this event, the visibility state has already been changed.
This example demonstrates how to listen for a
visibilitychange
event on a WebXR session, using
addEventListener()
to begin listening for the event:
navigator.xr.requestSession("inline").then((xrSession) => {
xrSession.addEventListener("visibilitychange", e => {
switch(e.session.visiblityState) {
case "visible":
case "visible-blurred":
mySessionVisible(true);
break;
case "hidden":
mySessionVisible(false);
break;
}
});
});
When a visibility state change occurs, the event is received and dispatched to a function
mySessionVisible()
, with a Boolean parameter indicating whether or not the session is presently being displayed to the user.
You can also create the event handler by assigning it to the
XRSession
's
onvisibilitychange
event handler property, like this:
xrSession.onvisibilitychange = (e) => {
/* event handled here */
};
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'visibilitychange event' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
visibilitychange
event
|
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
Navigator.xr
WebGLRenderingContext.makeXRCompatible()
XR
XRBoundedReferenceSpace
XRFrame
XRInputSource
XRInputSourceArray
XRInputSourceEvent
XRInputSourcesChangeEvent
XRPose
XRReferenceSpace
XRReferenceSpaceEvent
XRRenderState
XRRigidTransform
XRSessionEvent
XRSpace
XRView
XRViewerPose
XRViewport
XRWebGLLayer