我有一个页面,其中有一个浮动的、可拖动的模态框,让我在打开模态框时可以访问背景。除了背景中的垂直滚动条消失之外,以下方法在其他方面都有效。如何保持背景可滚动?
CSS
```css body.modal-open { overflow: hidden; } ```将上述代码更改为以下内容即可使背景可滚动:
```css body.modal-open { overflow: auto; } ```
#myModal {
position: relative;
}
.modal-dialog {
position: fixed;
width: 50%;
margin: 0;
padding: 10px;
}
HTML
<button id="openModal">Show Modal</button>
... lines of text ...
<!-- 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">
<h4 class="modal-title" id="myModalLabel">Draggable Modal</h4>
</div>
<div class="modal-body">
Modal Body
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
脚本
$('#openModal').click(function() {
if (!($('.modal.in').length)) {
$('.modal-dialog').css({
top: 0,
left: 0
});
}
$('#myModal').modal({
backdrop: false,
show: true
});
$('.modal-dialog').draggable({
handle: ".modal-header"
});
});