Disable scrolling in all mobile devices

后端 未结 13 1199
粉色の甜心
粉色の甜心 2020-11-28 03:18

This sounds like there should be a solution for it all over the internet, but I am not sure why I cannot find it. I want to disable Horizontal scrolling on mobile devices. B

13条回答
  •  长情又很酷
    2020-11-28 04:16

    For future generations:

    To prevent scrolling but keep the contextmenu, try

    document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });
    

    It still prevents way more than some might like, but for most browsers the only default behaviour prevented should be scrolling.

    For a more sophisticated solution that allows for scrollable elements within the nonscrollable body and prevents rubberband, have a look at my answer over here:

    https://stackoverflow.com/a/20250111/1431156

提交回复
热议问题