5
1 <!doctype html> 2 <html> 3 <head> 4 <meta name="description" content="jquery拖拽div" /> 5 <meta chart="utf-8"> 6 <title>js bin</title> 7 <style> 8 #div{ width:200px; height:200px; background:#ccc; position:absolute;} 9 #div h1{ height:30px; line-height:30px; font-size:12px; text-align:center;background: #f1f1f1;border-bottom: 1px solid #ccc;}10 </style>11 <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.10.2/jquery-1.10.2.js"></script>12 13 </head>14 <body>15 <div id="div"><h1端午手抄报>标题</h1></div>16 <script>17 $.fn.tdrag = function(options){18 var defaults = {19 },20 that = $(this),21 opts = $.exte秋季运动会作文nd({}, defaults, options),22 doc = $(document),23 width = $(window).width(),24 height = $(window).height(),25 startx = 0,26 starty = 0,27 lastx = 0,28 lasty = 0,29 box = that.parent(), // handler.parentnode30 handler = that[0],31 drag = {32 down: function(e){33 that.css('cursor', 'move');34 startx = e.clientx - parint(box.css('left'));35 starty = e.clienty - parint(box.css('top'));36 this.tcapture && this.tcapture(); // ie to prevent fast drag losing of object37 doc.on('moumove', drag.move);38 doc.on('mouup', drag.up);39 return fal; // chrome to prevent rolloughting screen, and the loss of the mou move style40 },41 move: function(e){42 lastx = e.clientx - startx;43 lasty = e.clienty - starty;44 lastx = math.max(0, math.min(width - box.outerwidth(), lastx));45 lasty = math消防知识题库.max(0, math.min(height - box.outerheight() - 1, lasty));46 box.css({'top': lasty + 'px', 'left': 春水lastx + 'px'});47 window.getlection ? window.getlection().removeallranges() : document.lection.empty(); // cancel the lected text48 e.stoppropagation();49 },50 up: function(){51 // that.css('cursor', 'auto');52 doc.off('moumove', drag.move);53 doc.off('mouup', drag.up);54 handler.releacapture && handler.releacapture(); // ie to prevent fast drag losing of object55 }56 };57 that.on('moudown', drag.down);58 }59 60 $('#div h1').tdrag();61 </script> 62 63 </body>64 </html>
本文发布于:2023-04-03 09:49:57,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/5e15261845e4483a1efc8671d62e6c56.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:div拖拽效果 JQuery.doc
本文 PDF 下载地址:div拖拽效果 JQuery.pdf
留言与评论(共有 0 条评论) |