Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable horizontal dragging? (webkit-overflow-scrolling: touch;)

We have vertical scrolling working fine with the following css for iOS 5's webkit scrolling 'touch', but we are still able to drag the page left and right. How can we disable left and right dragging?

Here is the CSS:

#page_content{

-webkit-overflow-scrolling: touch;
overflow-x:hidden;
overflow-y: scroll;   
position:absolute;
height: 460px;
width: 320px;

}

Here is the video:
http://dl.dropbox.com/u/1737103/scrolling.mov

Thanks in advance!

like image 429
user1155813 Avatar asked Jan 18 '12 09:01

user1155813


People also ask

How do I stop horizontal scrolling?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.

Why is my page scrolling horizontally?

In short: if you use width: 100vw on a page that has a vertical scrollbar you end up with a horizontal overflow. The easy fix is to use width: 100% instead. Percentages don't include the width of the scrollbar, so will automatically fit.

What is Webkit overflow scrolling touch?

The -webkit-overflow-scrolling CSS property controls whether or not touch devices use momentum-based scrolling for a given element.

How do I make my overflow scroll smoother?

You just need to add scroll-behavior: smooth; to your html style.


1 Answers

I found I could fix it by finding/fixing/removing elements that were wider than the width. For instance, if you have a 100% width on your container, and then an element inside has 100% width with margin or padding, even if the overflow is hidden on the container, the page will drag from side to side.

If you can make sure your elements inside don't horizontally spill outside the container, the page won't drag. If you need padding on a percentage width inside the container (like one element with 100% width, or two with 50% or whatever), 'box-sizing: border-box;' is the way forward.

like image 109
Ben Avatar answered Sep 30 '22 02:09

Ben