Problem:
On iOS the z-index
of a scrollable area is ignored when using -webkit-overflow-scrolling
. If two objects with -webkit-overflow-scrolling
overlap the lower one is scrolled instead of the one being displayed above.
How to reproduce:
Create two elements overlaying each other (with position: absolute
for example), one of them having a higher z-index
and add
.selector
{
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
to both of them. Both elements should have enough content to be scrollable.
Additionally add
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
to your <head>
. Then add the page to your home screen and launch it from there.
If you then try to scroll the upper element the element beneath is scrolled instead.
MCVE:
Alternatively just check out this pen. Launch the full version from your iOS device, add it to your home screen and launch from there.
Environment:
Tested on iPhone 5 and iPhone 6 with iOS 9.1 and iOS 9.3.2
Observations:
- The issue only occurs when launching the page/app from homescreen (pinned app) or inside a Xamarin Webview (might have something to do with UIWebView and WKWebView)
- After changing the device orientation (portrait/landscape) after page load the problem is fixed until the page is reloaded (maybe re-triggering layout fixed it?)
- Changing the lower elements
overflow-y
tohidden
via JS does fix the problem, however togglingoverflow
causes a repaint causing performance issues - Removing
height: 100%; width: 100%
fromhtml, body
fixes the problem as well, however those have to be set for percentage values to work properly
Needed is a proper solution / workaround to fix this issue without causing any troublesome side-effects. Also explanation of why this happens would be appreciated.