Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable scrolling in all mobile devices

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. Basically trying to achieve this:

body{    overflow-x:hidden  // disable horizontal scrolling. } 

This may be relevant information: I also have this in my head tag, because I also do not wish the user to be able to zoom:

<meta content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport' /> <meta name="viewport" content="width=device-width" /> 

Thanks

like image 906
Sammy Avatar asked May 14 '12 23:05

Sammy


People also ask

How do I get rid of horizontal scrolling on mobile?

Check all of your elements on "Mobile" view, and remove any high margins to the left or to the right side of the element. The mobile horizontal scrolling has been caused by setting a high fixed / minimum width for an element. Set elements to "auto", or just reduce the width on mobile devices.

How do I turn off horizontal scroll in CSS Mobile?

The horizontal scrollbar issue on mobile devices can be fixed by setting overflow to hidden. You can do this by using the Elementor Section settings or by adding CSS code.


2 Answers

html, body {   overflow-x: hidden; } body {   position: relative; } 

The position relative is important, and i just stumbled about it. Could not make it work without it.

like image 95
zeek Avatar answered Sep 23 '22 03:09

zeek


cgvector answer didn't work for me, but this did:

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

I wouldn't leave it just like that, a smarter logic is needed to select when to prevent the scrolling, but this is a good start.

Taken from here: Disable scrolling in an iPhone web application?

like image 36
Chango Avatar answered Sep 19 '22 03:09

Chango