简体   繁体   中英

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 smaller 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM