我在
http://bassmanager.com工作
如果你单击顶部的登录(或现在在页面上的任何地方注册),它会启动一个标准的Bootstrap 3.0模态窗口。
你会注意到当模态窗口打开时,浏览器滚动条只是消失一秒钟,然后回来。它在关闭它时也是一样。
我如何使它只是打开和关闭,没有浏览器滚动条互动。我已经看到堆栈上的人们有问题,但我找不到具体针对我的问题的答案,所以如果有人提出了这个请求,有人知道它,并希望链接到它,我会赞赏的帖子它。我已经搜索了约2个小时,然后发布。
解决方法
这是我发现在github当我搜索这个问题,对我来说它工作正常
js:
$(document).ready(function () {
$('.modal').on('show.bs.modal',function () {
if ($(document).height() > $(window).height()) {
// no-scroll
$('body').addClass("modal-open-noscroll");
}
else {
$('body').removeClass("modal-open-noscroll");
}
});
$('.modal').on('hide.bs.modal',function () {
$('body').removeClass("modal-open-noscroll");
});
})
css使用这个CSS如果你有nav-fixed-top和navbar-fixed-bottom:
body.modal-open-noscroll
{
margin-right: 0!important;
overflow: hidden;
}
.modal-open-noscroll .navbar-fixed-top,.modal-open .navbar-fixed-bottom
{
margin-right: 0!important;
}
或者用户这个css如果你有navbar-default
body.modal-open-noscroll
{
margin-right: 0!important;
overflow: hidden;
}
.modal-open-noscroll .navbar-default,.modal-open .navbar-default
{
margin-right: 0!important;
}