在Bootstrap Modal打开时阻止页面滚动

时间:2015-08-18 10:54:53

标签: twitter-bootstrap modal-dialog

如何在Bootstrap模态对话框打开时阻止页面滚动?

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button id="fechar" type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">Fechar</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

试试这个:

body.modal-open {
    overflow: hidden;
}

Bootstrap 3应该禁用overflow-x: hidden;.modal-open上默认模式的滚动,但我也发现它在某些情况下不起作用。