New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong $(window).innerHeight() and $(window).outerHeight() on mobile after scroll #4081

Closed
tendermario opened this Issue May 17, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@tendermario

tendermario commented May 17, 2018

Tested on Chrome on an android phone connected to my computer with remote debugging.

Expected behavior:
When I am scrolling through the page, $(window).innerHeight() (and outerHeight()) should be equal to the height of the browser page.

Actual behavior:
On a mobile device, the returned value for $(window).innerHeight() seems to be the same as the innerHeight on page load, which has the top address bar visible to make the screen smaller.

E.g.:
On page load, innerHeight() returns 560 for me. The page height is correct.
On scroll event, innerHeight() still returns 560. The browser has collapsed the address bar and the innerHeight is now 616 for me.

Open http://jsbin.com/vevicuvoxu/1/ on a phone and scroll down.

screen shot 2018-05-17 at 3 33 59 pm

Work around: window.innerHeight is still showing the correct value, so I had to use that for now.

@uedayuji

This comment has been minimized.

uedayuji commented May 21, 2018

We also encounter similar issue.

@timmywil

This comment has been minimized.

Member

timmywil commented May 21, 2018

Despite the confusion caused by the naming, the workaround here is to use .outerHeight which maps to window.innerHeight in the source. This is because .outerHeight includes scrollbar width/height. .innerHeight and .height use document.documentElement.clientHeight, which apparently does not adjust when the address bar collapses. There's a bit of extra weirdness when it comes to mobile, but since the workaround here is so simple, I'm inclined to close.

@timmywil timmywil closed this May 21, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Nov 17, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.