user782104
user782104

Reputation: 13555

How to prevent touchmove event move the background using jquery /javascript?

Currently I am developing a website for ipad Safari

I used

addEventListener('touchmove', function(e) { e.preventDefault(); }, true);

to prevent the background moving when dragging the content. The problem is when I allow some element to drag

    addEventListener('touchmove', function(e) { 
    //alert (e.target.id);
    if ( e.target.className != 'issues' && e.target.id != 'dialog' && e.target.id != 'issuesBox') 
    e.preventDefault(); 
    return false;
    }, true);

when I drag the element, it will drag the background too , how to fix this problem? I observe that this problem may caused by taphold ,Thanks.

Upvotes: 1

Views: 7643

Answers (1)

blurrcat
blurrcat

Reputation: 1328

Are you trying to prevent scroll on some element? Prevent default of both touchstart and touchmove events then. Here's doc from apple.

In my experience, prevent default on touchstart event is enough, e.g.,

$(document).on('touchstart', function (evt) {
    evt.preventDefault();
});

Upvotes: 2

Related Questions