亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery實(shí)現(xiàn)的簡單拖拽功能示例【測試可用】

 更新時間:2018年08月14日 11:18:48   作者:筱葭  
這篇文章主要介紹了jQuery實(shí)現(xiàn)的簡單拖拽功能,涉及jQuery基于事件響應(yīng)及頁面元素屬性動態(tài)操作實(shí)現(xiàn)拖拽功能的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了jQuery實(shí)現(xiàn)的簡單拖拽功能。分享給大家供大家參考,具體如下:

<!doctype html>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>chabaoo.cn jQuery拖拽</title>
    <style type="text/css">
      #box{
        position:fixed;
        left:100px;
        top:100px;
        background-color:red;
        width:300px;
        height:200px;
      }
      #out{
        height:2000px;
      }
    </style>
    <script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>
    <script>
      $(document).ready(function(){
        var drafting=false; 
        var offX,offY,mouseX,mouseY,winX,winY,x,y;
        $("#box").mousedown(function(event){
          event.stopPropagation();
          drafting=true;
        });
        $(document).mousemove(function(event){
          event.stopPropagation();
          var e=event||window.event;
          mouseX=e.pageX||e.clientX+$(document).scrollLeft();
          mouseY=e.pageY||e.clientY+$(document).scrollTop();
          winX=$("#box").offset().left-$(document).scrollLeft();
          winY=$("#box").offset().top-$(document).scrollTop();
          if(drafting==false){
            offX=mouseX-winX;
            offY=mouseY-winY;
          }
          x=mouseX-offX;
          y=mouseY-offY;
          $("#box").css({'left':x,'top':y});
        });
        $(document).mouseup(function(event){
          event.stopPropagation();
          drafting=false;
        });  
      });
    </script>
  </head>
  <body>
    <div id="box"></div>
    <div id="out"></div>
  </body>
</html>

這里使用在線HTML/CSS/JavaScript代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun,可得到如下測試效果:

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery拖拽特效與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery頁面元素操作技巧匯總》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論