禁用身体的滚动,但保持滚动条 [英] Deactivate body's scrolling but keep scroll bar

查看:53
本文介绍了禁用身体的滚动,但保持滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁用 body 的滚动条,但使其在屏幕上保持可见?例如,请参见facebook的剧院模式:

How do I disable body's scroll bar, but let it stay visible on screen? As an example see facebook's theatre mode:

推荐答案

这是您将要强制使用滚动条的唯一CSS:

This is the only CSS you will ned to force the scrollbars:

html{
    overflow-y: scroll;
}

如果内容小于窗口,则滚动条将被禁用,因此您将不得不使用一些脚本来将主体的大小调整为比窗口高度小至少 1px :

The scrollbars will be disabled if the content is smaller than the window, so you will have to use some script to resize the body to be at least 1px less then the window height:

$("body").css({ "height" : ($(window).height() - 1) + 'px', "overflow": "hidden" });

这篇关于禁用身体的滚动,但保持滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆