0

i wish to disable the vertical scroll for mobile devices. using :

body {overflow-x:hidden}

works for normal browsers but on mobile if there's an element wider than the screen it will allow side scrolling.

i have tried using this code:

jQuery(document).ready(function($) {
    var $body = $(document);
    $body.bind('scroll', function() {
        // "Disable" the horizontal scroll.
        if ($body.scrollLeft() !== 0) {
            $body.scrollLeft(0);
        }
    });
});

but it allows the side scrolling (on mobile) but "jumps" the scroll back to the right, this is not a perfect solution.

i have tried using this:

    <meta name="viewport" content=" width=device-width; initial-scale=1.0; user-scalable=0;" /> 
 $(document).bind("touchmove",function(event){
            event.preventDefault();
      });

this works perfect and disable the mobile scrolling totally, the problem is that it is disabling both horizontal and vertical scrolling (i wish to disable only the horizontal).

dumazy
  • 13,857
  • 12
  • 66
  • 113
user3003106
  • 193
  • 2
  • 12

1 Answers1

3

Try this:

html, body {
  overflow-x: hidden;
}
body {
  position: relative
}
Kurenai Kunai
  • 1,842
  • 2
  • 12
  • 22