相关疑难解决方法(0)

CSS3 100vh在移动浏览器中不恒定

我有一个非常奇怪的问题...在每个浏览器和移动版本中我遇到这种行为:

  • 加载页面时所有浏览器都有一个顶级菜单(例如显示地址栏),当您开始滚动页面时,该菜单会向上滑动.
  • 100vh仅在视口的可见部分计算,因此当浏览器栏向上滑动100vh时增加(以像素为单位)
  • 所有布局都重新绘制并重新调整,因为尺寸已更改
  • 对用户体验的糟糕跳跃效果

怎么能避免这个问题?当我第一次听到视口高度时,我很兴奋,我认为我可以将它用于固定高度块而不是使用javascript,但现在我认为唯一的方法是实际上javascript与一些resize事件......

您可以在以下位置查看问题:示例站点

任何人都可以帮我/建议一个CSS解决方案吗?


简单的测试代码:

/* maybe i can track the issue whe it occours... */
$(function(){
  var resized = -1;
  $(window).resize(function(){
    $('#currenth').val( $('.vhbox').eq(1).height() );
    if (++resized) $('#currenth').css('background:#00c');
  })
  .resize();
})
Run Code Online (Sandbox Code Playgroud)
*{ margin:0; padding:0; }

/*
  this is the box which should keep constant the height...
  min-height to allow content to be taller than viewport if too much text
*/
.vhbox{
  min-height:100vh;
  position:relative;
}

.vhbox .t{
  display:table;
  position:relative;
  width:100%;
  height:100vh;
}

.vhbox .c{ …
Run Code Online (Sandbox Code Playgroud)

html css css3 viewport-units

209
推荐指数
14
解决办法
12万
查看次数

标签 统计

css ×1

css3 ×1

html ×1

viewport-units ×1