jQuery實現div拖拽效果執行個體分析_jquery

來源:互聯網
上載者:User

本文執行個體分析了jQuery實現div拖拽效果。分享給大家供大家參考,具體如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title> New Document </title><script type="text/javascript" src="jquery-1.7.2.min.js"></script><style type="text/css">/*模組拖拽*/.drag{position:absolute;width:100px;height:100px;border:1px solid #ddd;background:#FBF2BD;text-align:center;padding:5px;top:100px;left:20px;cursor:move;}</style><script type="text/javascript">// 模組拖拽$(function(){var _move=false;//移動標記var _x,_y;//滑鼠離控制項左上方的相對位置  $(".drag").click(function(){    //alert("click");//點擊(鬆開後觸發)    }).mousedown(function(e){    _move=true;    _x=e.pageX-parseInt($(".drag").css("left"));    _y=e.pageY-parseInt($(".drag").css("top"));    $(".drag").fadeTo(20, 0.5);//點擊後開始拖動並透明顯示  });  $(document).mousemove(function(e){    if(_move){      var x=e.pageX-_x;//移動時根據滑鼠位置計算控制項左上方的絕對位置      var y=e.pageY-_y;      $(".drag").css({top:y,left:x});//控制項新位置    }  }).mouseup(function(){  _move=false;  $(".drag").fadeTo("fast", 1);//鬆開滑鼠後停止移動並恢複成不透明 });});</script></head><body><!--模組拖拽--> <div class="drag">這個可以拖動哦 ^_^</div></body></html>
$("#question_pic").bind("click",function(event){  event.stopPropagation(); //防止冒泡事件響應  $("#chat_question").hide("slow");});
$("#chatLineHolder").scrollTop(10000);//保持最下一行,不用滾

更多關於jQuery相關內容感興趣的讀者可查看本站專題:《jQuery拖拽特效與技巧總結》、《jQuery常見經典特效匯總》、《jQuery擴充技巧總結》、《jquery選取器用法總結》及《jquery常用操作技巧匯總》

希望本文所述對大家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.