I have a div
that is 100% height, 70% viewport height, and overflow:scroll
.
Now I want to create an overlaying div
which touch devices can use to scroll the whole page instead of the div
.
I created a div
with position:absolute
and full page height. If Android users drag on this div
, the whole page scrolls, like expected. However, on iOS7 the underlying div
is scrolled, like the touch event goes right trough the div
.
JSFiddle
.scrollDiv{
width:100%;
height:200px;
overflow-y:scroll;
border:solid 1px #f00;
-webkit-overflow-scrolling: touch;
}
.pageScroller{
position:absolute;
right:0;
top:0;
bottom:0;
width:50%;
background-color: rgba(0,0,0,0.7);
}
If you use iOS7 and drag on the page div
over the scrolling div
, the scrolling div
is scrolled instead of the page.
Does anybody know a solution for this?
The most straightforward way for disabling scrolling on websites is to add overflow: hidden on the <body> tag. Depending on the situation, this might do the job well enough. If you don't have to support older versions of iOS, you can stop reading here. // src/utils/scroll-lock.
Click the Apple menu at the top-left of the screen. Select System Preferences. Click the General preference tab - it's the first one, at the top. Under the Show scroll bars section, select the Always option.
Approach: A simple solution to this problem is to set the value of the “overflow” property of the body element to “hidden” whenever the modal is opened, which disables the scroll on the selected element.
Disabling scroll with only CSS. There's another way to disable scrolling that is commonly used when opening modals or scrollable floating elements. And it is simply by adding the CSS property overflow: hidden; on the element you want to prevent the scroll.
On your .pageScroller
scroller element, add the overflow-y: scroll;
and -webkit-overflow-scrolling: touch;
attributes, together with a postive z-index
. That prevents the scroll action to reach the "layer" beneath.
.pageScroller{
position:absolute;
right:0;
top:0;
bottom:0;
width:50%;
z-index: 1;
background-color: rgba(0,0,0,0.7);
overflow-y:scroll;
-webkit-overflow-scrolling: touch;
}
Check this JSfiddle: http://jsfiddle.net/R9Ut6/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With