user2240329
user2240329

Reputation: 97

Stop full page to scroll in ipad web app

I have ipad web app i am scrolling the particular div it is working fine but problem is that when user touces out side the div then also the page scrolls i want to stop the page scroll and make div only to scroll.

I used


 document.ontouchmove=function(e) { e.preventDefault()};

but it stops scrolling on whole page also on div.

here is the index file link i am working on

http://codepad.org/7RE5vx74

Upvotes: 0

Views: 489

Answers (1)

imbecile
imbecile

Reputation: 468

Give the div a class (say, 'scrollThis'). Handle the touchmove event in such a way that, if the target of the touchmove event is not the div, to prevent the scroll. Else, let it take place.

$('body').on('touchmove', function (e) {
    if (!$('.scrollThis').has($(e.target)).length) //check if the div isn't being scrolled
      e.preventDefault();
});

I have used this in an iOS/android web app, so i can vouch that it works.

Upvotes: 1

Related Questions