简体   繁体   English

限制使用javascript在特定div窗口上的html内部对象拖动

[英]Restrict dragging of object inside html on specific div window using javascript

I have used this script and I was wondering if it's possible to prevent the dragging of image when it is at the edge of the div window inside html? 我使用了此脚本,我想知道当它位于html内div窗口的边缘时是否可以防止图像拖动?

Here is the link: 链接在这里:

<https://jsfiddle.net/61t6nn4a/2/>

Any tips would be awesome thank you. 任何提示都会很棒,谢谢。

You can make your life easier by using jQuery. 您可以使用jQuery使您的生活更轻松。

jQueryUI has a draggable functionnality, check the documentation here : http://api.jqueryui.com/draggable/ jQueryUI具有可拖动功能,请在此处查看文档: http ://api.jqueryui.com/draggable/

HTML: HTML:

<div class="container">
    <img src="http://www.zpixel.com/staging/test/image.png" class="dragme">
</div>

JS: JS:

$(".dragme").draggable({
    containment: ".container"
});

Here is the JSFiddle : https://jsfiddle.net/v28r9v3r/1/ 这是JSFiddle: https ://jsfiddle.net/v28r9v3r/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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