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

XRSession 接口的 onsqueezestart event handler property can be set to a function which is then invoked to handle the squeezestart event that's sent when the user successfully begins a primary squeeze action on a WebXR input device. These actions represent the user squeezing or tightly gripping an object or controller.

To learn more about how to use and handle WebXR controller inputs, see Inputs and input sources .

句法

xrSession.onsqueezestart = squeezestartHandlerFunction;
					

A function to be invoked whenever the XRSession 接收 squeezestart 事件。

范例

This snippet of code adds a simple handler for the squeezestart event, which responds only to events on the user's dominant hand by getting the target ray, then calling a function findObjectUsingRay() to identify the object that the user is pointing at. This object is then stored in a heldObject 变量在 user object we're using to represent user information.

xrSession.onsqueezestart = event => {
  if (event.inputSource.handedness == user.handedness) {
    let targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, myRefSpace;
    if (targetRayPose) {
      user.heldObject = findObjectUsingRay(targetRayPose.transform);
    }
  }
};
					

规范

规范 状态 注释
WebXR 设备 API
The definition of 'XRSession.onsqueezestart' in that specification.
工作草案 初始定义。

浏览器兼容性

No compatibility data found. Please contribute data for "api.XRSession.onsqueezestart" (depth: 1) to the MDN 兼容性数据存储库 .

另请参阅

元数据

  • 最后修改: