disable long-press vibration in javascript for iOS
Asked Answered
C

1

9

working on a webgame with ThreeJS. On iOS, a longpress creates a small haptic vibration feedback after 0.5s have passed.

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?

Each are implemented as such:

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

Thanks!

Crenate answered 30/1, 2021 at 5:6 Comment(0)
M
2

It seems that you have to explicity select a container and attach the event handling to that cotainer.

HTML:

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

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/

Example that does not work when attaching to the document: https://jsfiddle.net/gyfbh35t/3/

Mitsue answered 14/1, 2022 at 18:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.