欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡(jiǎn)單的jQuery拖拽排序效果的實(shí)現(xiàn)(增強(qiáng)動(dòng)態(tài))

 更新時(shí)間:2017年02月09日 14:13:58   作者:bayaci  
這篇文章主要介紹了簡(jiǎn)單的jQuery拖拽排序效果的實(shí)現(xiàn)(增強(qiáng)),增強(qiáng)動(dòng)態(tài)增加div效果,代碼簡(jiǎn)單,很容易實(shí)現(xiàn),需要的朋友可以參考下

增強(qiáng)動(dòng)態(tài)增加Div效果

原來(lái)沒(méi)有新建動(dòng)作,分析代碼后發(fā)現(xiàn)很容易增強(qiáng)~~

<!DOCTYPE HTML> 
 <html> 
 <head> 
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 <title>測(cè)試的拖拽功能</title> 
 <style type="text/css"> 
 body, div { margin: 0; paading: 0; font-size: 12px; } 
 body { width:100%; margin: 0 auto; } 
 ul, li { margin: 0; padding: 0; list-style: none; } 
 .clear { clear: both; width: 1px; height: 0px; line-height: 0px; font-size: 1px; } 
 .drag_module_box { width: 600px; height: auto; margin: 25px 0 0 0; padding: 5px; border: 1px solid #f00; } 
 .drag_module_box1 { width: 600px; height: auto; margin: 25px 0 0 0; padding: 5px; border: 1px solid #f00; } 
 .drag_module_main { position: static; width: 600px; height: 80px; margin-bottom: 5px; border: 1px solid blue; background: #ccc; } 
 .drag_module_maindash { position: absolute; width: 600px; height: 80px; margin-bottom: 5px; border: 1px dashed blue; background: #ececec; opacity: 0.7; } 
 .drag_module_hide { width: 600px; height: 80px; margin-bottom: 5px; } 
 .drag_module_dash { position: sta;tic; width: 600px; height: 80px; margin-bottom: 5px; border: 1px dashed #f00; }; 
 </style> 
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
 <script type="text/javascript"> 
 $(document).ready( function () { 
  //來(lái)源:http://www.cnblogs.com/web-ed2/archive/2011/09/19/2181819.html 
   var range = { x: 0, y: 0 };//鼠標(biāo)元素偏移量 
   var lastPos = { x: 0, y: 0, x1: 0, y1: 0 }; //拖拽對(duì)象的四個(gè)坐標(biāo) 
   var tarPos = { x: 0, y: 0, x1: 0, y1: 0 }; //目標(biāo)元素對(duì)象的坐標(biāo)初始化 
   var theDiv = null, move = false;//拖拽對(duì)象 拖拽狀態(tài) 
   var theDivId =0, theDivHeight = 0, theDivHalf = 0; tarFirstY = 0; //拖拽對(duì)象的索引、高度、的初始化。 
   var tarDiv = null, tarFirst, tempDiv; //要插入的目標(biāo)元素的對(duì)象, 臨時(shí)的虛線對(duì)象 
  function loopbox(){ //循環(huán)初始化 
     $(".drag_module_box").find(".drag_module_main").each(function(){ 
      console.log( 'find' ); 
       $(this).mousedown(function (event){ 
         //拖拽對(duì)象 
         theDiv = $(this); 
         //鼠標(biāo)元素相對(duì)偏移量 
         range.x = event.pageX - theDiv.offset().left; 
         range.y = event.pageY - theDiv.offset().top; 
         theDivId = theDiv.index(); 
         theDivHeight = theDiv.height(); 
         theDivHalf = theDivHeight/2; 
         move = true; 
         theDiv.attr("class","drag_module_maindash"); 
         // 創(chuàng)建新元素 插入拖拽元素之前的位置(虛線框) 
         $("<div class='drag_module_dash'></div>").insertBefore(theDiv); 
       }); 
     }); 
  } 
  loopbox(); 
   $(".drag_module_box").mousemove(function(event) { 
    console.log( 'mousemove' ); 
     if (!move) return false; 
     lastPos.x = event.pageX - range.x; 
     lastPos.y = event.pageY - range.y; 
     lastPos.y1 = lastPos.y + theDivHeight; 
     // 拖拽元素隨鼠標(biāo)移動(dòng) 
     theDiv.css({left: lastPos.x + 'px',top: lastPos.y + 'px'}); 
     // 拖拽元素隨鼠標(biāo)移動(dòng) 查找插入目標(biāo)元素 
     var $main = $('.drag_module_main'); // 局部變量:按照重新排列過(guò)的順序 再次獲取 各個(gè)元素的坐標(biāo), 
     tempDiv = $(".drag_module_dash"); //獲得臨時(shí) 虛線框的對(duì)象 
     $main.each(function () { 
       tarDiv = $(this); 
       tarPos.x = tarDiv.offset().left; 
       tarPos.y = tarDiv.offset().top; 
       tarPos.y1 = tarPos.y + tarDiv.height()/2; 
       tarFirst = $main.eq(0); // 獲得第一個(gè)元素 
       tarFirstY = tarFirst.offset().top + theDivHalf ; // 第一個(gè)元素對(duì)象的中心縱坐標(biāo) 
       //拖拽對(duì)象 移動(dòng)到第一個(gè)位置 
       if (lastPos.y <= tarFirstY) { 
           tempDiv.insertBefore(tarFirst); 
       } 
       //判斷要插入目標(biāo)元素的 坐標(biāo)后, 直接插入 
       if (lastPos.y >= tarPos.y - theDivHalf && lastPos.y1 >= tarPos.y1 ) { 
         tempDiv.insertAfter(tarDiv); 
       } 
     }); 
   }).mouseup(function(event) { 
    console.log( 'mouseup' ); 
    if(theDiv==null) return false; 
     theDiv.insertBefore(tempDiv); // 拖拽元素插入到 虛線div的位置上 
     theDiv.attr("class", "drag_module_main"); //恢復(fù)對(duì)象的初始樣式 
     $('.drag_module_dash').remove(); // 刪除新建的虛線div 
     move=false; 
   }); 
   $("#drag_module_insert").click(function(){ 
    $("#drag_module_box1").html($("#drag_module_box1").html()+$("#drag_module_box2").html()); 
    loopbox(); 
   }); 
   $("#drag_module_seque").click(function(){ 
    $(".drag_module_box").find(".drag_module_main").each(function(){ 
      console.log($(this).attr('id')); 
    }); 
   }); 
 }); 
 </script> 
 </head> 
 <body>  
 <div class="drag_module_box" id="drag_module_box1"> 
   <div class="drag_module_main" id="main1">div1</div> 
   <div class="drag_module_main" id="main2">div2</div> 
   <div class="drag_module_main" id="main3">div3</div> 
   <div class="drag_module_main" id="main4">div4</div> 
   <div class="drag_module_main" id="main5">div5</div> 
   <div class="drag_module_main" id="main6">div6</div> 
 </div> 
 <div class="drag_module_box1" id="drag_module_box2"> 
  <div class="drag_module_main" id="main_first">div7</div> 
 </div> 
 <input type="button" value="新建" id="drag_module_insert"/> 
 <input type="button" value="確定" id="drag_module_seque"/> 
 </body> 
 </html> 

相關(guān)文章

  • JavaScript實(shí)現(xiàn)的滾動(dòng)公告特效【基于jQuery】

    JavaScript實(shí)現(xiàn)的滾動(dòng)公告特效【基于jQuery】

    這篇文章主要介紹了JavaScript實(shí)現(xiàn)的滾動(dòng)公告特效,結(jié)合完整實(shí)例形式詳細(xì)分析了基于jQuery實(shí)現(xiàn)的頁(yè)面元素間歇修改,最終達(dá)到滾動(dòng)公告效果的相關(guān)操作技巧,需要的朋友可以參考下
    2019-07-07
  • jQuery實(shí)現(xiàn)全選按鈕

    jQuery實(shí)現(xiàn)全選按鈕

    這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)全選按鈕,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • jQuery EasyUI API 中文文檔 - Tree樹(shù)使用介紹

    jQuery EasyUI API 中文文檔 - Tree樹(shù)使用介紹

    jQuery EasyUI API 中文文檔 - Tree樹(shù)使用介紹,需要的朋友可以參考下。
    2011-11-11
  • JQuery調(diào)用WebServices的方法和4個(gè)實(shí)例

    JQuery調(diào)用WebServices的方法和4個(gè)實(shí)例

    你是不是經(jīng)常作這種開(kāi)發(fā),前端用JS寫(xiě)邏輯,后端用aspx或者ashx作服務(wù)?你是不是經(jīng)常在請(qǐng)求aspx的時(shí)候在查詢(xún)字符串中拼接諸如a.aspx?method=getDepartmetn&param1=1&param2=2的字符串?
    2014-05-05
  • jQuery實(shí)現(xiàn)頁(yè)面頂部顯示的進(jìn)度條效果完整實(shí)例

    jQuery實(shí)現(xiàn)頁(yè)面頂部顯示的進(jìn)度條效果完整實(shí)例

    這篇文章主要介紹了jQuery實(shí)現(xiàn)頁(yè)面頂部顯示的進(jìn)度條效果,以完整實(shí)例形式分析了jQuery基于animate與setTimeout定時(shí)觸發(fā)實(shí)現(xiàn)進(jìn)度條漸進(jìn)顯示功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-12-12
  • Jquery+Ajax實(shí)現(xiàn)跨域訪問(wèn)

    Jquery+Ajax實(shí)現(xiàn)跨域訪問(wèn)

    這篇文章介紹了Jquery實(shí)現(xiàn)Ajax跨域訪問(wèn)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • jquery實(shí)現(xiàn)的仿天貓側(cè)導(dǎo)航tab切換效果

    jquery實(shí)現(xiàn)的仿天貓側(cè)導(dǎo)航tab切換效果

    這篇文章主要介紹了jquery實(shí)現(xiàn)的仿天貓側(cè)導(dǎo)航tab切換效果,涉及jquery鼠標(biāo)事件及鏈?zhǔn)讲僮鲗?shí)現(xiàn)頁(yè)面元素樣式遍歷切換效果的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-08-08
  • jquery實(shí)現(xiàn)彈出層效果實(shí)例

    jquery實(shí)現(xiàn)彈出層效果實(shí)例

    這篇文章主要介紹了jquery實(shí)現(xiàn)彈出層效果的方法,實(shí)例分析了jQuery實(shí)現(xiàn)彈出層的技巧,涉及jQuery操作頁(yè)面元素與樣式的技巧,需要的朋友可以參考下
    2015-05-05
  • jquery 跨域訪問(wèn)問(wèn)題解決方法(筆記)

    jquery 跨域訪問(wèn)問(wèn)題解決方法(筆記)

    對(duì)于js跨域訪問(wèn),在先前也曾碰到過(guò),但可能并沒(méi)有認(rèn)真去對(duì)待,可能查看過(guò)相關(guān)資料,但當(dāng)著兩天再次碰到這個(gè)問(wèn)題時(shí),走了不少?gòu)澛凡耪业絾?wèn)題原因。記下這次解決過(guò)程,為自己不再?gòu)?qiáng)大的記憶力默哀一下。
    2011-06-06
  • jQuery.deferred對(duì)象使用詳解

    jQuery.deferred對(duì)象使用詳解

    這篇文章主要為大家詳細(xì)介紹了jQuery.deferred對(duì)象的使用方法,內(nèi)容很全面,感興趣的小伙伴們可以參考一下
    2016-03-03

最新評(píng)論