js拖拽 jquery實現

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   java   sp   

 1 <!doctype html> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html;charset=utf-8"/> 5 <title>拖拽</title> 6 <style> 7 #drag{ 8 position:absolute; 9 width:200px;10 height:100px;11 background-color:red;12 }13 </style>14 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>15 <script type="text/javascript">16 $(function(){17 18 var is_drag=false;19 var x=0;20 var y=0;21 22 $("#drag").mouseover(function(){$(this).css("cursor","move");});23 24 $("#drag").mousedown(function(){25 is_drag=true;26 x=event.offsetX;27 y=event.offsetY;28 $(this).css("cursor","move");29 });30 31 $("#drag").mouseup(function(){is_drag=false;});32 33 $(document).mousemove(function(){34 if(!is_drag){return;}35 $("#drag").css({"left":event.clientX-x,"top":event.clientY-y,"cursor":"move"});36 });37 38 });39 </script>40 </head>41 <body>42 <div id="drag"></div>43 </body>44 </html>
View Code

 

js拖拽 jquery實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.