模式隐藏时滚动条未恢复
Scrollbar not restored on modal hide
我有一个模式,可以通过单击按钮打开。
打开此模式后,我得到 2 个滚动条,
- 模态模式优先
- 秒 html/body
我试过如下删除滚动条:
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
你需要把那个给 body
:
$('body').css('overflow','auto');
你能试试这个吗:
$("#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;
}
我有一个模式,可以通过单击按钮打开。 打开此模式后,我得到 2 个滚动条,
- 模态模式优先
- 秒 html/body
我试过如下删除滚动条:
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
你需要把那个给 body
:
$('body').css('overflow','auto');
你能试试这个吗:
$("#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;
}