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

The WebXR event select is sent to an XRSession when one of the session's input sources has completed a primary action . Examples of comon kinds of primary action are users pressing triggers or buttons, tapping a touchpad, speaking a command, or performing a recognizable gesture when using a video tracking system or handheld controller with an accelerometer.

冒泡 Yes
可取消 No
接口 XRInputSourceEvent
事件处理程序特性 onselect

For details on how the selectstart , select ,和 selectend events work, and how you should react to them, see Primary actions in Inputs and input sources .

范例

以下范例使用 addEventListener() to set up a handler for the select event. The handler fetches the pose representing the target ray for tracked-pointer inputs and sends the pose's transform to a function called myHandleSelectWithRay() .

xrSession.addEventListener("select", event => {
  if (event.inputSource.targetRayMode == "tracked-pointer") {
    let targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace,
                              myRefSpace);
    if (targetRayPose) {
      myHandleSelectWithRay(targetRayPose.transform);
    }
  }
});
					

You can of course also set up a handler for select events by setting the XRSession 对象的 onselect event handler property to a function that handles the event:

xrSession.onselect = event => {
  if (event.inputSource.targetRayMode == "tracked-pointer") {
    let targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace,
                              myRefSpace);
    if (targetRayPose) {
      myHandleSelectWithRay(targetRayPose.transform);
    }
  }
};
					

规范

规范 状态 注释
WebXR 设备 API
The definition of 'select event' 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
select 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

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: