bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Overlay scrolling on the iPhone scrolls the body

Open yazinsai opened this issue 13 years ago • 6 comments

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.

yazinsai avatar Aug 10 '13 09:08 yazinsai

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

mdo avatar Aug 13 '13 05:08 mdo

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.

yazinsai avatar Aug 13 '13 07:08 yazinsai

Issue reproduced here for reference. When accessed from a mobile device, the body starts scrolling after reaching the bottom of the modal.

yazinsai avatar Sep 24 '13 18:09 yazinsai

We are able to reproduce this issue in iphone 5s also. Is there is any workaround for this until it gets fixed?

JeganGitHub avatar Dec 16 '13 16:12 JeganGitHub

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);
            }
        });
    }

jordanneenan avatar May 06 '14 10:05 jordanneenan

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.

ajmueller avatar Dec 08 '14 22:12 ajmueller