content “jumps” vertically on Chrome iOS with viewport sizing when address bar is hidden/displayed [closed]

人盡茶涼 提交于 2019-12-10 18:30:09

问题


Im' having different sections on my website and I want some of them to take the full viewport height. So I size with height: 100vh;

On Chrome iOS, this results in the content slightly "jumping vertically" whenever the address bar is hidden or displayed again. In particular, this happens whenever user scrolls in one direction then in another direction.

You can see an example here (to look on Chrome mobile browser): www.PlasticPalacePeople.com

Any idea how to solve that? (and, ideally, to keep my sections taking the full viewport height)

P.S.: there seems to be no problem with Safari for iOS and embedded Facebook web browser

Thank you


回答1:


Hey I ran across this same problem. While this doesn't solve the annoyingness of the CSS Viewport Height resizing issue in mobile chrome it does seem to be a viable workaround.

Just change "jumbotron" below to whatever your css selector is for the element/elements you want full height.

HTML

<div class="jumbotron"></div>

CSS

.jumbotron {
  height: 100vh;
}

JS

function calcVH() {
    $('.jumbotron').innerHeight( $(this).innerHeight() );
}
(function($) { 
  calcVH();
  $(window).on('resize orientationchange', function() {
    calcVH();
  });
})(jQuery);

What it does is it sets an height of the section when the page loads to the viewport height. Seems to work although I wish this could be done without javascript.

Update: Here's my complete answer

https://stackoverflow.com/a/40156488/1728524



来源:https://stackoverflow.com/questions/38280077/content-jumps-vertically-on-chrome-ios-with-viewport-sizing-when-address-bar-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!