Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent underlying div from scrolling in iOS Safari

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?

like image 597
NLAnaconda Avatar asked Apr 06 '14 14:04

NLAnaconda


People also ask

How do I stop scrolling In iOS?

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.

How do I fix my scroll on safari?

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.

How do I stop my body from scrolling?

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.

How do I stop my screen from scrolling CSS?

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.


1 Answers

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/

like image 170
Marcus Olsson Avatar answered Sep 27 '22 18:09

Marcus Olsson