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

XRSession 接口的 onsqueezeend event handler property is a function to be invokedn when the squeezeend event sent to an XRSession primary squeeze action ends. This is sent immediately after the squeeze event, which announces the successful completion of the squeeze action. The squeezeend event handler is where you handle closing out a squeeze action whether it was successfully completed or not.

To learn more about how the sequence of squeeze events works, see Primary squeeze actions in Inputs and input sources .

句法

xrSession.onsqueezeend = squeezeendHandlerFunction;
					

A function to be invoked whenever the XRSession 接收 squeezestart event, indicating the ending of a primary squeeze action.

范例

This snippet of code adds a simple handler for the squeezeend event, which responds only to events on the user's dominant hand. In response to the end of the squeeze operation, this code looks to see if there is an object currently being held by the user by checking to see if the variable user.heldObject contains a reference to an object representing the held item.

heldObject has an object reference, that object is passed to a function called cancelObjectDrag() , which would be written to return the object to its original position. This takes care of the situation in which the drag is aborted or canceled.

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

This code presumes that if the user actually intentionally completed the drag, user.heldObject 将是 null here. That's because (in this example, at least) the handler for the squeeze event has already dropped the object into its new location and then cleared the value of heldObject to indicate that the user is no longer holding anything.

规范

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

浏览器兼容性

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

另请参阅

元数据

  • 最后修改: