So I noticed that mobile Chrome calculates the address bar into the viewport height. Because of this using height: 100vh
on an element doesn't work because when the address bar scrolls the viewport height changes.
I was actually able to find a question that had the same issue here on ios, but after investigating further I realized that this happens on all mobile Chrome browsers. When the address bar scrolls out of the viewport and then again when scrolls into the viewport, the viewport height changes.
This causes any element using vh
to recalculate which makes the page jump. It's extremely annoying when using a background image because it causes the image to resize on scrolling.
Here's the code and an example
.jumbotron {
background-image: url(http://example.com/image.png);
background-size: cover;
background-position: top;
background-repeat: no-repeat;
height: 100vh;
}
You'll only be able to see the issue when scrolling up and down using mobile chrome.
My question is, I would like to know is there any way around this or if not how to calculate full height on mobile chrome without causing the page to jump (css or js).
http://s.codepen.io/bootstrapped/debug/qadPkz
Update: So as far as using jquery here's what I came up with which seems to work pretty well:
function calcVH() {
$('.jumbotron').innerHeight( $(this).innerHeight() );
}
$(window).on('load resize orientationchange', function() {
calcVH();
});
I'd love to be able to do this without javascript though if someone has a CSS alternative that they know works.