Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict scrolling of a mobile site but allow access to potentially retracted address bar

I have a repo up and running if you're interested in contributing to solutions.

I've run into an interesting problem while constructing a mobile site.

I am setting 'overflow: hidden;' to html/body when a drawer is toggled. This is so the window can't be scrolled, and the drawer - which is scrollable - on reaching it's limits doesn't scroll the page (e.preventDefault(); & e.stopPropagation(); simply don't do the trick).

This all works great. Fantastic if this was a Phonegap app. However - as this is a website, the inconsistent overflow setting creates a usability issue with the browser's 'fullscreen mode'. 'Fullscreen mode' is when the address bar is hidden upon scrolling down the page. When scrolling up the bar will reappear. When toggling the drawer the browser is essentially locked in either 'non fullscreen mode' or 'fullscreen mode'. The latter is the real issue - as users are simply unable to access the address bar - and gives the impression the browser has locked up or something weird.

Any bright ideas as to how (probably with Javascript) a scroll/touchmove could still give the effect of entering/exiting 'fullscreen mode'? I've had a play with the fullscreen API, but that's proper fullscreen, not just the address bar.

here are some screenshots:

example

  1. site loads, we can see the address bar

  2. site is scrollable as expected, browser enters 'fullscreen mode'

  3. we toggle the drawer to open - the site is now unresponsive (besides the drawer scrolling and any gestures [via AngularJS directives] I've got to hide the drawer)

  4. the drawer toggled when the address bar is visible. Good for usability, but the expected 'fullscreen mode' when using a site doesn't occur (would be nice to have the real estate).

EDIT2: https://medium.com seems to achieve what I'm after.

EDIT3: Some success with a invisible absolute positioned div sitting on top of everything - but that has it's own issues.

like image 282
Patrick Avatar asked Jan 12 '14 17:01

Patrick


People also ask

How do I stop my page from scrolling?

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.

How do I stop my pop up from opening when I scroll?

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 make a scroll overlay?

For touch devices, try adding a 1px wide, 101vh min-height transparent div in the wrapper of the overlay. Then add -webkit-overflow-scrolling:touch; overflow-y: auto; to the wrapper. This tricks mobile safari into thinking the overlay is scrollable, thus intercepting the touch event from the body.


1 Answers

Rather than setting overflow: hidden; on body when the drawer is out, how about making the drawer position: fixed; overflow-y: auto;, that way the user can make the choice to scroll the body to get to the address bar or the drawer.

Just out of interest, what does Firefox for Android do in this situation? It might be worth filing a bug with the Chromium team if Firefox doesn't display similar usability problems.

EDIT: I've taken a look at the code at https://github.com/patrickmarabeas/marabeas.io when running in Android Chrome and Android Firefox via their respective ADB-enabled remote debuggers (really good tools!).

I've come to the conclusion that there isn't a nice way to get the address bar to show once it's hidden when body has overflow: hidden on it.
There is however after a hacky way!

Shift the main scrollable area from body to a div, in this case, #content. Then, position: absolute; body and make it fill the viewport plus some extra height when on mobile. Given below is the relevant CSS applied on the mobile browsers:

body {
    position: absolute;
    top: 0;
    bottom: -100px;
    left: 0;
    right: 0;
}

#content {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
}

Then, as the browser is looking for body to be doing the scrolling as to whether or not to display the address bar, get the #content scroll to be linked with the main body scroll, though this may not be having an effect!:

var lastScrollTop = 0;
document.getElementById('content').addEventListener('scroll', function(e) {
    var currentScrollTop = document.getElementById('content').scrollTop;
    if(currentScrollTop < lastScrollTop) {
        // Upwards scroll!
        document.body.scrollTop -= 10;
    } else {
        // Downwards scroll!
        document.body.scrollTop += 10;
    }
    lastScrollTop = currentScrollTop;
 });

I'm sending you a pull request now: https://github.com/patrickmarabeas/marabeas.io/pull/5

like image 140
jedifans Avatar answered Oct 17 '22 09:10

jedifans