简体   繁体   English

为什么引导模态在关闭模态并锚定到页面后会删除我的滚动条

[英]Why bootstrap modal removes my scroll bar after closing modal and anchoring to page

I have a bootstrap modal and and button inside it aside from the close button. 除了关闭按钮外,我还有一个引导程序模版和一个按钮。 So what I want is when I click the button, the modal will close and will navigate to the same page via anchor tag. 所以我想要的是当我单击按钮时,模态将关闭,并将通过定位标记导航到同一页面。 This works but problem is the modal is removing or disabling the scroll bar. 这可行,但是问题是模式删除或禁用了滚动条。 The modal thinks as if the modal is still open. 模态认为模态仍然是开放的。

I have this: 我有这个:

$( "#silverB" ).click(function() {
  $("#myModal").hide();
  $(document.body).scrollTop($('#optin').offset().top);
});

You should not retire the modal using .hide() . 您不应该使用.hide()退出modal Instead use this: 而是使用此:

$("#myModal").modal("hide");

Because, bootstrap adds more classes to body ( .modal-open ) when the modal is opened. 因为,启动模式时,引导程序会向主体( .modal-open )添加更多类。 But when you "hide" the modal, they are not reset. 但是,当您“隐藏”模态时,不会重置它们。

From the docs : 文档

.modal('hide')

Manually hides a modal. 手动隐藏模式。 Returns to the caller before the modal has actually been hidden (ie before the hidden.bs.modal event occurs).` 在模态实际被隐藏之前(即在hidden.bs.modal事件发生之前)返回到调用者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM