Reputation: 97
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
Upvotes: 0
Views: 489
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