Prevent scroll while the Modal Bootstrap is open

1

How do I prevent the scroll scroll while the Bootstrap Modal Dialog is open?

<!-- 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>
    
asked by anonymous 18.08.2015 / 12:53

1 answer

-1

When the modal is displayed, the bootstrap automatically adds the class modal-open , and removes it when it is hidden. Putting in your css this excerpt:

body.modal-open {     overflow: hidden; }

OBS: Does not work correctly in Safari and some older versions of Internet Explorer.

    
18.08.2015 / 13:56