Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable vertical scroll in mobile device only fory body (not also for div with overflow: auto)

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.

like image 805
Borja Avatar asked Feb 02 '26 13:02

Borja


1 Answers

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

like image 137
Borja Avatar answered Feb 05 '26 03:02

Borja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!