![](/img/trans.png)
[英]Hiding and showing bootstrap 4 modal at the same time will hide the browser's scrollbar
[英]Scrollbar not restored on modal hide
我有一个模态,可以通过单击按钮打开。 打开此模式后,我会看到2个滚动条,
我尝试删除滚动条,如下所示:
if ($(".dialog-popup-open").length > 0) {
$('html').css('overflow','hidden');
}
$(".closeButton").off("click").on("click", function () {
$('html').css('overflow','scroll');
//$('html').css('overflow','inherit');
}
滚动条完美隐藏,但模式关闭时无法恢复。 有什么想法吗?
我尝试了scroll
和inherit
你能试试这个吗:
$("#openModal").click(function(){ //code to open the overlay //.... //.... //add modalActive class to html tag $("html").addClass("modalActive"); }); $(".closeButton").off("click").on("click", function () { //code to close the modal overlay //... //... //remove modalActive class from html $('html').removeClass("modalActive"); });
.modalActive{ overflow: hidden; }
你需要把它给body
:
$('body').css('overflow','auto');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.