Reputation: 3559
I would like disable vertical scroll in all mobile devices and i found this:
document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });
that works very well...
but in this way i disable scroll also for a div (my menu) that has overflow: auto
.
In dekstop browser to avoid anything with JQuery when $(window).scroll()
add overflow: hidden
to body
. And in that way i don't have problem, but with native javascript code yes... i'm new in javascript.
So with jquery i was able disable scroll of body eccept div with overflow: auto, but not with that js code.
I hope you can help me and sorry for my english.
Upvotes: 3
Views: 17261
Reputation: 3559
i solved always with jQuery:
when i want disable scroll add:
$("body").css({"overflow":"hidden",'position':'fixed'});
with body: fixed
i'm sure that also with mobile device is impossible scroll the page (except div that has overflow: auto
Upvotes: 8
Reputation:
you could disable the scrool on just the body part by making it the size of the screen and then make it so it doesnt scrol
document.body.addEventListener('touchmove', function(e){
document.getElementsByTagName('body')[0]. style .height = "100vh";
document.getElementsByTagName('body')[0]. style. overflow = "hidden";
});
Upvotes: 0