最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
jQuery怎么實(shí)現(xiàn)拖拽排序效果-創(chuàng)新互聯(lián)

這篇文章給大家分享的是有關(guān)jQuery怎么實(shí)現(xiàn)拖拽排序效果的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

成都創(chuàng)新互聯(lián)主營蓮都網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā),蓮都h5小程序定制開發(fā)搭建,蓮都網(wǎng)站營銷推廣歡迎蓮都等地區(qū)企業(yè)咨詢

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

jQuery怎么實(shí)現(xiàn)拖拽排序效果

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

 
  
  
  
 測試的拖拽功能 
  
 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; }; 
  
  
  
 $(document).ready( function () { 
  //來源: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 }; //拖拽對象的四個坐標(biāo) 
   var tarPos = { x: 0, y: 0, x1: 0, y1: 0 }; //目標(biāo)元素對象的坐標(biāo)初始化 
   var theDiv = null, move = false;//拖拽對象 拖拽狀態(tài) 
   var theDivId =0, theDivHeight = 0, theDivHalf = 0; tarFirstY = 0; //拖拽對象的索引、高度、的初始化。 
   var tarDiv = null, tarFirst, tempDiv; //要插入的目標(biāo)元素的對象, 臨時的虛線對象 
  function loopbox(){ //循環(huán)初始化 
     $(".drag_module_box").find(".drag_module_main").each(function(){ 
      console.log( 'find' ); 
       $(this).mousedown(function (event){ 
         //拖拽對象 
         theDiv = $(this); 
         //鼠標(biāo)元素相對偏移量 
         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)建新元素 插入拖拽元素之前的位置(虛線框) 
         $("
").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)移動       theDiv.css({left: lastPos.x + 'px',top: lastPos.y + 'px'});       // 拖拽元素隨鼠標(biāo)移動 查找插入目標(biāo)元素       var $main = $('.drag_module_main'); // 局部變量:按照重新排列過的順序 再次獲取 各個元素的坐標(biāo),       tempDiv = $(".drag_module_dash"); //獲得臨時 虛線框的對象       $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); // 獲得第一個元素         tarFirstY = tarFirst.offset().top + theDivHalf ; // 第一個元素對象的中心縱坐標(biāo)         //拖拽對象 移動到第一個位置         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ù)對象的初始樣式       $('.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'));      });     });   });                  div1
     div2
     div3
     div4
     div5
     div6
   
       div7
   
            

感謝各位的閱讀!關(guān)于“jQuery怎么實(shí)現(xiàn)拖拽排序效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.cdcxhl.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。


網(wǎng)頁題目:jQuery怎么實(shí)現(xiàn)拖拽排序效果-創(chuàng)新互聯(lián)
鏈接URL:http://fisionsoft.com.cn/article/cdodci.html

其他資訊