jquery经典实例之拖动面板

ゝ一世哀愁。 2021-07-24 18:55 439阅读 0赞
  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="GBK">
  5. <title></title>
  6. </head>
  7. <body>
  8. <div style="position: absolute;border: 1px solid yellow;width: 500px;">
  9. <div id="title" style="background-color:powderblue;height: 30px;">
  10. <strong>标题</strong>
  11. </div>
  12. <div style="height: 300px;">
  13. 内容
  14. </div>
  15. </div>
  16. <script src="jquery-1.5.1.js"></script>
  17. <script>
  18. $(function () {
  19. $('#title').mouseover(function () {
  20. $(this).css('cursor','move');
  21. }).mousedown(function (e) {
  22. var _event = e || widows.event;
  23. var ord_x = _event.clientX;
  24. var ord_y = _event.clientY;
  25. var parent_left = $(this).parent().offset().left;
  26. var parent_top = $(this).parent().offset().top;
  27. $(this).bind('mousemove',function (e) {
  28. var _new_event = e || window.event;
  29. var new_x = _new_event.clientX;
  30. var new_y = _new_event.clientY;
  31. var x = parent_left + (new_x - ord_x);
  32. var y = parent_top + (new_y - ord_y);
  33. $(this).parent().css('left',x+'px');
  34. $(this).parent().css('top',y+'px');
  35. })
  36. }).mouseup(function () {
  37. $(this).unbind('mousemove');
  38. });
  39. })
  40. </script>
  41. </body>
  42. </html>

发表评论

表情:
评论列表 (有 0 条评论,439人围观)

还没有评论,来说两句吧...

相关阅读

    相关 鼠标拖动面板

    之前写过一篇关于form表单验证随笔,后来添加了一点点内容,使得可以使用鼠标将其拖动,为了完整性,还是写一遍随笔吧;加上这部分内容后,HTML和CSS部分,也进行了少量修改,这