【问题标题】:Page darkens and can't be scrolled up or down after closing modal关闭模态后页面变暗无法向上或向下滚动
【发布时间】:2018-07-12 14:10:21
【问题描述】:

当我点击一个按钮时,我有两个模态框同时出现。当我在两个模态框之外单击时,它们将同时关闭。但问题是在同时关闭 2 个模态框后发生的。页面变暗了,我无法滚动页面!

var modalA = document.getElementById('projectModalSecond2');

// Get the modal
var modal = document.getElementById('projectModal2');

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  //alert(event.target)
  if (event.target == modal) {
    modal.style.display = "none";
    modalA.style.display = "none";
  }

  if (event.target == modalA) {
    modalA.style.display = "none";
    modal.style.display = "none";
  }
}
<div tabindex="0" class="modal fade pop-up-box-index pop-up-box-margin-left" id="projectModal2">
  <div class="modal-dialog">
    <div class="modal-content pop-up-box-top-margin pop-up-box-index">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><b>Substrate Map Station Controller (SMSC)</b></h4>
      </div>
      <div class="modal-body">
        <img src="assets/img/gallery/ULT_SDT1.jpg" alt="" class="img-responsive">
        <p>Full range of station controller.</p>
        <br>
      </div>
    </div>
  </div>
</div>

<div tabindex="0" class="modal fade pop-up-box-index pop-up-box-margin-right" id="projectModalSecond2">
  <div class="modal-dialog">
    <div class="modal-content pop-up-box-top-margin pop-up-box-index">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><b>Substrate Map Editor (SME)</b></h4>
      </div>
      <div class="modal-body">
        <img src="assets/img/gallery/ULT_SDT2.jpg" alt="" class="img-responsive">
        <p>Unit and Substrate map traceability</p>
        <br><br>
      </div>
    </div>
  </div>
</div>

【问题讨论】:

标签: javascript html css


【解决方案1】:

似乎您正在使用 Bootstrap,在这种情况下,您可能正在使用 jQuery。我看到您正在使用纯 javascript 来完成这项工作,但对于这种特殊情况,您应该考虑使用 jQuery 来关闭您的模式。

$('#projectModalSecond2').modal('hide');
$('#projectModal2').modal('hide');

【讨论】:

  • 我补充说,我现在可以滚动页面,但它仍然变暗。我认为有某种层?
  • 如果您尝试喜欢 (stackoverflow.com/questions/46215070/…) 的答案怎么样。移除背景:$(".modal-backdrop").remove();
  • @JavaThoughts 如果您在打开模式时签入代码中附加的类,那么您正在谈论的黑色层称为覆盖层。这个黑色层有一个单独的类,其中显示了模态。您可以根据需要将其删除,但这是 Boostrap 模态的默认功能。
  • @YoannesGeissler 我添加了那个,但它仍然是一样的,黑暗并且可以滚动但不能点击
  • @Code_Ninja 当我单击深色叠加层时,我似乎找不到 Dreamweaver 中显示的代码。如果它是一门课,那么如果我能找到它,它应该会更容易(如果有区别的话,它是一个购买的模板)。我必须删除它,如果我不这样做,模式关闭后它会变暗。
猜你喜欢
  • 2019-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-18
  • 2021-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多