如果我在模态中有模态,则模态滚动无法工作

时间:2017-02-28 11:52:12

标签: html twitter-bootstrap bootstrap-modal

我在模态中有一个模态,它可以正常工作。但是当我看到第一个模态超出屏幕并且出现第一个模态的滚动时它会起作用但是当我打开第二个模态并关闭它时,第一个模态将不会滚动。

这是一个向你展示的片段。

<!DOCTYPE html>
<html lang="en">
<head>
  <title></title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#test1">Open Modal 1 </button>



<div id="test1" class="modal fade" role="dialog" style="z-index: 1400;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      
      <div class="modal-body">
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>

      	<button type="button" class="btn btn-info btn-lg" data-toggle="modal"      data-target="#test2">Open Modal 2</button>
      	
      </div>      
    </div>
  </div>
</div>

<div id="test2" class="modal fade" role="dialog" style="z-index: 1600;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      
      <div class="modal-body">
      	
        content
      	
      </div>      
    </div>
  </div>
</div>
  

</body>
</html>

有人知道为什么当我打开和关闭第二个模态时它无法滚动。 在此先感谢。

2 个答案:

答案 0 :(得分:1)

设置溢出:auto;到你的#test1容器。这将是解决方案

#test1 {
overflow: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <title></title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#test1">Open Modal 1 </button>



<div id="test1" class="modal fade" role="dialog" style="z-index: 1400;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      
      <div class="modal-body">
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>

      	<button type="button" class="btn btn-info btn-lg" data-toggle="modal"      data-target="#test2">Open Modal 2</button>
      	
      </div>      
    </div>
  </div>
</div>

<div id="test2" class="modal fade" role="dialog" style="z-index: 1600;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      
      <div class="modal-body">
      	
        content
      	
      </div>      
    </div>
  </div>
</div>
  

</body>
</html>

答案 1 :(得分:0)

来自Bootstrap docs

  

“不支持多个打开模式   确保不打开模态,而另一个模态仍然可见。一次显示多个模态需要自定义代码。“

所以你需要自定义代码来考虑每个模态的滚动位置和高度。