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

The WebXR event selectend is sent to an XRSession when one of its input sources ends its primary action or when an input source that's in the process of handling an ongoing primary action is disconnected without successfully completing the action. Primary actions include things like 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
事件处理程序特性 onselectend

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 establish handlers for the selection events: selectstart , selectend ,和 select . This snippet is the core of an event handler to allow the user to grab objects in the scene and move them around.

In this case, a single function is used to handle all three events, allowing them to share certain code that's the same regardless of which of the three events is received. Only after completing those tasks does the onSelectionEvent() function below dispatch the action out to a specialized function to handle things.

After checking to ensure that the received event is a tracked-pointer event (the only kind we handle here), the target ray's pose is obtained using getPose() .

If the target ray pose was fetched successfully, the code then uses the value of 事件 property type to route control to an appropriate function to handle the event which arrived:

  • For selectstart events, a myBeginTracking() function is called with the target ray pose's matrix myBeginTracking() function would presumably start the presentation of the object-dragging process, using the transform to perform a hit test, determining which object to pick up. myBeginTracking() returns an object representing the object the user has begun to drag.
  • Upon receiving a select event, the myDropObject() function is called with the target object and the current target ray pose transform as inputs. This places the object into its new position in the world and triggers any effects that may arise from doing so (like scheduling an animation of a splash if dropped in water, etc).
  • selectend event results in a myStopTracking() function being called with the object being dragged and the final target ray pose's transform.
xrSession.addEventListener("selectstart", onSelectionEvent);
xrSession.addEventListener("select", onSelectionEvent);
xrSession.addEventListener("selectend", onSelectionEvent);
function onSelectionEvent(event) {
  let source = event.inputSource;
  let targetObj = null;
  if (source.targetRayMode != "tracked-pointer") {
    return;
  }
  let targetRayPose = event.frame.getPose(source.targetRaySpace, myRefSpace);
  if (!targetRayPose) {
    return;
  }
  switch(event.type) {
    case "selectstart":
      targetObj = myBeginTracking(targetRayPose.matrix);
      break;
    case "select":
      myDropObject(targetObj, targetRayPose.matrix);
      break;
    case "selectend":
      myStopTracking(targetObj, targetRayPose.matrix);
      break;
  }
}
					

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

xrSession.onselectstart = onSelectionEvent;
xrSession.onselect = onSelectionEvent;
xrSession.onselectend = onSelectionEvent;
					

规范

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

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: