[英]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
. 效果很好......但是这样我也禁用了滚动,因为div(我的菜单)有
overflow: auto
。
In dekstop browser to avoid anything with JQuery when $(window).scroll()
add overflow: hidden
to body
. 在dekstop浏览器中,当
$(window).scroll()
添加overflow: hidden
到body
时,用JQuery避免任何事情。 And in that way i don't have problem, but with native javascript code yes... i'm new in javascript. 并且以这种方式我没有问题,但使用本机JavaScript代码是...我是javascript的新手。
So with jquery i was able disable scroll of body eccept div with overflow: auto, but not with that js code. 所以使用jquery我能够禁用body eccept div的scroll with overflow:auto,但不能使用那个js代码。
I hope you can help me and sorry for my english. 我希望你能帮助我,对不起我的英语。
i solved always with jQuery: 我总是用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
与
body: fixed
我确定也与移动设备无法滚动页面(除了有overflow: auto
div overflow: auto
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 你可以通过使它成为屏幕的大小来禁用身体部位的scrool,然后使它不滚动
document.body.addEventListener('touchmove', function(e){
document.getElementsByTagName('body')[0]. style .height = "100vh";
document.getElementsByTagName('body')[0]. style. overflow = "hidden";
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.