我问一个非常奇怪的问题…每个浏览器和手机版本都遇到了这个行为:
当您开始滚动页面时,在加载页面和显示地址栏时,所有浏览器都有顶部菜单。
由于100vh只在视口的可见部分计算,因此滑动浏览器栏100vh会以像素为单位增加
由于调整了大小,所有布局都将重新绘制和重新调整
用户体验差的跳跃效果
怎么才能避免这个问题? 我第一次听到viewport-height很兴奋。 我本以为可以用那个固定高度块istead用javascript,但现在唯一的办法实际上是javascript和一些resize事件…
谁能提出帮助我的CSS解决方案吗?
简单的测试代码:
/* maybeicantracktheissuewheitoccours . * /
$ (功能() ) )。
var resized=-1;
$(window ).resize (function ) )。
$('#currenth ' ).val($ ).VHbox ) ).eq ) (1).height );
if (已限定) $(#currenth ).CSS ) ) background:#00c );
() )
. resize (;
() )
*{ margin:0; padding:0; }
/*
thisistheboxwhichsouldkeepconstanttheheight .
min-heighttoallowcontenttobetallerthanviewportiftoomuchtext
*/
. vhBox{
min-height:100vh;
position:relative;
}
. vhBox .t{
显示:表;
position:relative;
width:100%;
高海拔:100 VH;
}
. vhBox .c{
height:100%;
display :表蜂窝;
垂直对准:米;
文本对齐3360中心;
}
thisdivheightshouldbe 100 % ofviewportandkeepthisheightwhenscrollingpage
thisdivheightshouldbe 100 % ofviewportandkeepthisheightwhenscrollingpage