100% window 高度的移动导航栏,无论内容如何

Mobile navbar with 100% window height regardless of content

我有一个页面的移动版本。内容足够用户必须在他的移动设备上滚动。单击图标时,移动导航栏从左侧滑入,body 变为 overflow: hidden;,因此内容不再滚动。有没有办法使导航栏的高度为 window(而不是文档)的 100%,以便用户可以进一步在导航栏内滚动? 目前滑入和导航高度由 Javascript 控制,但我正在寻找 CSS 解决方案。有人可以帮忙吗?

// CSS
#mobile_nav {
    width: 300px;
    position: fixed;
    top: 0;
    left: -300px;
    z-index: 10000;
    overflow: auto;
}

// JS
jQuery("#mobile_button").on("click", function() {
    jQuery("#mobile_nav")
        .css({ height: jQuery(window).height() });
        .stop(true)
        .animate({ left: 0 })
    ;
    jQuery("body").css({ overflow: "hidden" });
});

您可以像这样使用视口单位:

    height: 100vh;

您可以查看浏览器对此的支持 css 属性 here.