XRSession.onsqueezeend - Web APIs 编辑
Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The XRSession
interface's onsqueezeend
event handler property is a function to be invokedn when the squeezeend
event sent to an XRSession
when a 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.
Syntax
xrSession.onsqueezeend = squeezeendHandlerFunction;
Value
A function to be invoked whenever the XRSession
receives a squeezestart
event, indicating the ending of a primary squeeze action.
Examples
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.
If 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
will be 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.
Specifications
Specification | Status | Comment |
---|---|---|
WebXR Device API The definition of 'XRSession.onsqueezeend' in that specification. | Working Draft | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
- Inputs and input sources
- The other
onsqueeze*
handlers:onsqueezestart
andonsqueeze
- The
squeeze
,squeezestart
, andsqueezeend
events
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论