Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable long-press vibration in javascript for iOS

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!

like image 812
David Lester Avatar asked Jan 30 '21 05:01

David Lester


People also ask

How do I turn off Long press vibration?

Scroll down to “System Sound/Vibration Control.” The bottom section of toggles is for vibration. Toggle on or off any of the things you'd like to change.

How do I stop my iPhone from vibrating when I touch it?

Turn off all vibrations: Go to Settings > Accessibility > Touch, then turn off Vibration. Note: This setting turns off vibrations for earthquake, tsunami, and other emergency alerts.


1 Answers

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/

like image 162
sg1234 Avatar answered Oct 03 '22 08:10

sg1234