【发布时间】:2015-10-29 16:54:03
【问题描述】:
我正在使用 Bootstrap v3.3.5。每次触发模态框时,滚动条都会隐藏,从而使网页抖动。你能建议我一个修复方法吗?
网址:http://goo.gl/kwn7YH 模态框由右侧的查询按钮触发。我尝试添加 cutsom JS 来删除边距/填充但没有用:
$(document).on( 'hidden.bs.modal', '.modal', function() {
$(document.body).removeClass( 'modal-scrollbar' );
}).on( 'show.bs.modal', '.modal', function() {
// Bootstrap's .modal-open class hides any scrollbar on the body,
// so if there IS a scrollbar on the body at modal open time, then
// add a right margin to take its place.
if ( $(window).height() < $(document).height() ) {
$(document.body).addClass( 'modal-scrollbar' );
}
});
})(window.jQuery);
});
【问题讨论】:
-
您发布的链接无效。它转到您的本地主机。
-
@Shaunak 更新链接! goo.gl/kwn7YH我迷失在代码中:)
-
也许这对你有用。它不会隐藏滚动条,而是阻止它。 stackoverflow.com/questions/8701754/…
-
FWIW 在 Bootstrap 上有一个关于这个的巨大讨论,你有很多解决方法。您必须自己尝试一下,因为它们中的大多数都需要完整的站点结构和 css 知识。看看:github.com/twbs/bootstrap/issues/9855
标签: javascript jquery html css twitter-bootstrap