JQuery Drag can drag past the Containment element with auto-scroll
I've been playing around with JQuery's drag and drop when i noticed I can drag out of the containment element when the window is too small and there's a scrollbar. Basically with the below code, what you can do is make your window sma开发者_运维知识库ller until you have vertical scroll bars; then drag the inner div downwards until it goes past the outer div.
Anyone know a workaround or have encountered this problem elsewhere (maybe I'm doing it wrong)? Currently I just disable the scroll option, but I'd rather it be able to scroll.
<html>
<head>
<script src="jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.8.11.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".draggable").draggable();
$(".draggable").draggable("option", "containment", ".parentdraggable");
});
</script>
</head>
<body>
<div class="parentdraggable" style="border:1px solid black;min-width:400px;min-height:400px;">
<div class="draggable" style="border:1px solid black">Hi</div>
</div>
</body>
</html>
You have to set scroll to false. Sample Code: http://jsfiddle.net/Sgoettschkes/PyyWG/
I believe this solves the problem.
精彩评论