码迷,mamicode.com
首页 > 其他好文 > 详细

拖拽Draggable

时间:2015-11-29 00:54:17      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Constrain Draggable - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Constrain Draggable</h2>
  14. <p>The draggable object can only be moved within its parent container.</p>
  15. <div style="margin:20px 0;"></div>
  16. <div class="easyui-panel" style="position:relative;overflow:hidden;width:500px;height:300px">
  17. <div class="easyui-draggable" data-options="onDrag:onDrag" style="width:100px;height:100px;background:#fafafa;border:1px solid #ccc;">
  18. </div>
  19. </div>
  20. <script>
  21. function onDrag(e){
  22. var d = e.data;
  23. if (d.left < 0){d.left = 0}
  24. if (d.top < 0){d.top = 0}
  25. if (d.left + $(d.target).outerWidth() > $(d.parent).width()){
  26. d.left = $(d.parent).width() - $(d.target).outerWidth();
  27. }
  28. if (d.top + $(d.target).outerHeight() > $(d.parent).height()){
  29. d.top = $(d.parent).height() - $(d.target).outerHeight();
  30. }
  31. }
  32. </script>
  33.  
  34. </body>
  35. </html>

拖拽Draggable

标签:

原文地址:http://www.cnblogs.com/takemybreathaway/p/5003833.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!