Overlay scrolling on the iPhone scrolls the body
I noticed that scrolling an overlay scrolls the body when the overlay has been scrolled completely. This is unlike the behavior that's exhibited
I'm guessing this is due to the iPhone/iPad scrolling issues mentioned in this article. I tested this with an iPhone 4S, running iOS6.1.
Note: The issue was encountered in both the Chrome browser, and the native Safari browser.
There's currently no known solution to this as far as I can tell. If someone has a fix–I've Googled and fiddled for long enough—do let us know! <3
Gotcha- I'll look into it and let you know. Thanks!
Sent from my iPhone
On Aug 13, 2013, at 8:50 AM, Mark Otto [email protected] wrote:
There's currently no known solution to this as far as I can tell. If someone has a fix–I've Googled and fiddled for long enough—do let us know! <3
— Reply to this email directly or view it on GitHub.
Issue reproduced here for reference. When accessed from a mobile device, the body starts scrolling after reaching the bottom of the modal.
We are able to reproduce this issue in iphone 5s also. Is there is any workaround for this until it gets fixed?
I found a hacky way around this. If you cache the current scroll position of the document, set the body to position: fixed when you open your overlay the body content no longer scrolls in the background.
When you close your overlay, you set the body's position to relative and then use your cached scroll position with .scrollTop() to scroll back to where you were.
Here's the code I wrote:
if (navigator.userAgent.match(/(iPhone|iPod|iPad)/i)) {
$(window).scroll(function () {
$currentScrollPos = $(document).scrollTop();
})
$('.menu-button').click(function () {
if ($('.menu-overlay').hasClass('active')) {
$('body').css({
'position': 'fixed'
});
localStorage.cachedScrollPos = $currentScrollPos;
} else {
$('body').css({
'position': 'relative'
});
$('body').scrollTop(localStorage.cachedScrollPos);
}
});
}
I ran into a similar issue on a project of mine that doesn't use Bootstrap, but the same concept applies. I have fixed navigation that sits offscreen and when it's onscreen, scrolling the navigation eventually scrolls the body underneath unless I implement the fix suggested by @jordanneenan. While that works, it would be awesome to find a CSS-only solution for this...some day.