简体   繁体   English

为 iOS 禁用 javascript 中的长按振动

[英]disable long-press vibration in javascript for iOS

working on a webgame with ThreeJS.使用 ThreeJS 开发网页游戏。 On iOS, a longpress creates a small haptic vibration feedback after 0.5s have passed.在 iOS 上,长按会在 0.5 秒后产生小的触觉振动反馈。

Since I'd like the user to be able to hold their finger down to walk around, this is a distraction.因为我希望用户能够按住手指四处走动,所以这会分散注意力。

I've already got preventDefault and stopPropagation in play for touchStart , touchEnd , touchMove , touchCancel , and contextMenu , what am I missing?我已经为touchStarttouchEndtouchMovetouchCancelcontextMenu使用了 preventDefault 和 stopPropagation ,我错过了什么?

Each are implemented as such:每个都是这样实现的:

function onTouchStart(event) {
     event.preventDefault();
     event.stopPropagation();
     ...

Thanks!谢谢!

It seems that you have to explicity select a container and attach the event handling to that cotainer.看来您必须明确 select 一个容器并将事件处理附加到该容器。

HTML: HTML:

<body><div id="body">
    <div>
        test
    </div>
</div></body>

Javascript: Javascript:

document.getElementById('body').addEventListener("touchstart", (e)=>{
    e.preventDefault();
    e.stopPropagation();
});

Example that works when attaching to the #body div: https://jsfiddle.net/gyfbh35t/2/附加到#body div 时的示例: https://jsfiddle.net/gyfbh35t/2/

Example that does not work when attaching to the document: https://jsfiddle.net/gyfbh35t/3/附加到文档时不起作用的示例: https://jsfiddle.net/gyfbh35t/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM