简体   繁体   English

如何验证在框中移动的可拖动文本?

[英]How to validate the draggable text moving around the boxes?

I have to validate the draggable text before touching the top, left, right and bottom. 在触摸顶部,左侧,右侧和底部之前,我必须验证可拖动文本。 Before i have to alert the user with 1px margin border inside the box. 在我必须用框内的1px边距边框警告用户之前。 It should not move after that 1px margin. 在1px保证金之后它不应该移动。 How to achieve it using javascript or jquery? 如何使用javascript或jquery实现它?

https://jsfiddle.net/uf44m36j/1/ https://jsfiddle.net/uf44m36j/1/

 $('.dragme').draggable({ containment: ".drag-parent" });

If I didn't misunderstand it, you want to notify user before the rectangle hits the border, don't you? 如果我没有误解它,你想在矩形撞到边框之前通知用户,不是吗? You can use drag event for this case, and identify the position in it. 您可以对此案例使用拖动事件,并标识其中的位置。

Documentation: http://api.jqueryui.com/draggable/#event-drag 文档: http//api.jqueryui.com/draggable/#event-drag

Here is the JsFiddle: https://jsfiddle.net/yusrilmaulidanraji/uf44m36j/2/ 这是JsFiddle: https ://jsfiddle.net/yusrilmaulidanraji/uf44m36j/2/

  $('.dragme').draggable({ containment: ".drag-parent", drag: function( event, ui ) { if (ui.position.top == 1) { //tell user the box almost hits the top } if (ui.position.left == 1) { //tell user the box almost hits the left } } }); 
 .dragme { border-radius: 0.5em; width: 12em; height: 8em; padding: 1em; font-family: "Montserrat", "Arial"; background-color: #00C5CD; color: white; } .drag-parent { border: 0.1em solid #BA064E; width: 45em; height: 20em; } 
 <script src="//code.jquery.com/jquery-1.9.1.js"></script> <script src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script> <link href="//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet"/> <div class="drag-parent"> <div class="dragme">Drag me!</div> </div> 

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

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