Javascript Jquery 可拖动与引导模式,滚动奇怪的行为
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27120579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery draggable with bootstrap modal, scroller strange behaviour
提问by Maris
I'm trying to use bootstrap modal popup with jquery-ui draggable functionality. I use it like this:
我正在尝试使用具有 jquery-ui 可拖动功能的引导模式弹出窗口。我像这样使用它:
// Bootstrap modal
$(element).modal({ keyboard: false,
show: value
});
// Jquery draggable
$(element).draggable({
handle: ".modal-header"
});
But when I try to drag the popup right scroller is dragging with popup. Thx for any advance.
但是,当我尝试拖动弹出式右侧滚动条时,正在拖动弹出式菜单。感谢任何预付款。
回答by Bass Jobsen
i think you should apply draggableon the .modal-dialogclass, see:
我认为您应该申请draggable该.modal-dialog课程,请参阅:
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<div>
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<script>
$('.modal').modal({ keyboard: false,
show: true
});
// Jquery draggable
$('.modal-dialog').draggable({
handle: ".modal-header"
});
</script>
回答by Gaurav Jain
Nice answer by @Bass Jobsen
@Bass Jobsen 的回答很好
However I felt that sometimes we might need to dynamically resize the modal. So here extending Bass's solution for resizable and draggable modal
但是我觉得有时我们可能需要动态调整模式的大小。所以这里扩展了 Bass 的可调整大小和可拖动模式的解决方案
Addition
添加
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" />
and
和
$('.modal-content').resizable();
$('.modal-content').resizable();
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<div>
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<script>
$('.modal').modal({ keyboard: false,
show: true
});
// Jquery draggable
$('.modal-dialog').draggable({
handle: ".modal-header"
});
$('.modal-content').resizable();
</script>
Further, you can specify the minHeight and minWidth
此外,您可以指定 minHeight 和 minWidth
$('.modal-content').resizable({
minHeight: 100,
minWidth: 100
});

