drag.htm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title></title>
  6. <link href="../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
  7. <script src="../../lib/jquery/jquery-1.5.2.min.js" type="text/javascript"></script>
  8. <script src="../../lib/ligerUI/js/core/base.js" type="text/javascript"></script>
  9. <script src="../../lib/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
  10. <script type="text/javascript">
  11. function changeZIndex(obj)
  12. {
  13. $(obj).css("z-index", 2).siblings("div").css("z-index", 1);
  14. }
  15. $(function ()
  16. {
  17. // $('#rr1,#rr3').ligerDrag({
  18. // onStartDrag: function (current)
  19. // {
  20. // changeZIndex(current.target[0]);
  21. // }
  22. // });
  23. //拖动时不使用代理
  24. var d = $('#rr1').ligerDrag({ proxy: false });
  25. //使用头部,使用默认代理
  26. $('#rr2').ligerDrag({ handler: '#rr2h' });
  27. //使用自定义代理
  28. $('#rr3').ligerDrag({ proxy: function ()
  29. {
  30. var div = $("<div class='proxy'>proxy</div>");
  31. div.width($(this).width());
  32. div.height(30);
  33. div.appendTo('body');
  34. return div;
  35. }
  36. });
  37. //使用副本代理
  38. $('#rr4').ligerDrag({ proxy: 'clone' });
  39. //使用副本代理,并归位
  40. var drag5 = $('#rr5').ligerDrag({ proxy: 'clone', revert: true });
  41. //其实这里可以写成:
  42. //var drag5 = new $.ligerui.controls.Drag({ proxy: 'clone', revert: true, target: $('#rr5')[0] });
  43. //绑定一个事件,改变拖动时的鼠标图标,也可以把onStartDrag作为参数传入,用bind的好处是可以多次绑定
  44. drag5.bind('StartDrag', function ()
  45. {
  46. //这里this就是drag5,组件管理器,类型为$.ligerui.controls.Drag
  47. //drag5.cursor = 'not-allowed';
  48. this.cursor = 'not-allowed';
  49. });
  50. //这里利用receive属性定义了一个接收区域
  51. var drag6 = $('#rr6').ligerDrag({ proxy: 'clone', revert: true
  52. , receive: '#receive'
  53. });
  54. drag6.bind('StartDrag', function ()
  55. {
  56. this.cursor = 'not-allowed';
  57. });
  58. //当进入区域时
  59. drag6.bind('DragEnter', function (receive, source, e)
  60. {
  61. drag6.cursor = "pointer";
  62. $(receive).find(".message").html("进入区域");
  63. });
  64. //在区域移动
  65. drag6.bind('DragOver', function (receive, source, e)
  66. {
  67. $(receive).find(".message").html("在区域移动 " + e.pageX + ":" + e.pageY);
  68. });
  69. //离开区域
  70. drag6.bind('DragLeave', function (receive, source, e)
  71. {
  72. this.cursor = "not-allowed";
  73. $(receive).find(".message").html("离开区域");
  74. });
  75. //在区域释放
  76. drag6.bind('Drop', function (receive, source, e)
  77. {
  78. source.hide();
  79. $(receive).find(".txt").val(source.find(".txt").val());
  80. $(receive).find(".message").html("在区域释放");
  81. });
  82. });
  83. </script>
  84. <style type="text/css">
  85. .proxy
  86. {
  87. border: 1px splid #333;
  88. position: absolute;
  89. z-index: 4;
  90. background: #f1f1f1;
  91. }
  92. .box
  93. {
  94. width: 80px;
  95. height: 80px;
  96. border: 1px solid #ddd;
  97. }
  98. .txt
  99. {
  100. margin: 2px;
  101. width: 60px;
  102. border: 1px solid #333;
  103. }
  104. </style>
  105. </head>
  106. <body style="padding: 10px">
  107. <div id="rr1" class="box" style="top: 100px; background: #A6DBD8; position: absolute;"></div>
  108. <div id="rr2" class="box" style="top: 100px; left: 100px; background: #AFCCF1; position: absolute;">
  109. <div id="rr2h" style="width: 100%; height: 30px; background: #95BBEC; line-height: 30px;">
  110. </div>
  111. </div>
  112. <div id="rr3" class="box" style="top: 100px; left: 200px; background: #DA9188; position: absolute;">
  113. </div>
  114. <div id="rr4" class="box" style="top: 100px; left: 300px; background: #9CD88A; position: absolute;">
  115. </div>
  116. <div id="rr5" class="box" style="top: 100px; left: 400px; background: #D09CC5; position: absolute;">
  117. </div>
  118. <div id="rr6" class="box" style="top: 100px; left: 500px; background: #E2DC6B; position: absolute;">
  119. <input type="text" class="txt" value="内容" />
  120. </div>
  121. <div id="receive" style="top: 300px; left: 100px; position: absolute; width: 200px;
  122. height: 200px; padding: 10px; border: 1px solid #888;" onSelectStart= "return false">
  123. <p><input type="text" class="txt" value="" /></p>
  124. <p>第6个例子 可以拖动到这里,试试</p>
  125. <p class="message"></p>
  126. </div>
  127. <div id="message">
  128. </div>
  129. <div style="display: none">
  130. </div>
  131. </body>
  132. </html>