茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    jQuery實(shí)現(xiàn)div橫向拖拽排序的簡單實(shí)例
    來源:易賢網(wǎng) 閱讀:1681 次 日期:2016-07-28 14:06:51
    溫馨提示:易賢網(wǎng)小編為您整理了“jQuery實(shí)現(xiàn)div橫向拖拽排序的簡單實(shí)例”,方便廣大網(wǎng)友查閱!

    下面小編就為大家?guī)硪黄猨Query實(shí)現(xiàn)div橫向拖拽排序的簡單實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。

    實(shí)例如下:

    <!DOCTYPE HTML>

    <html>

    <head>

    <meta charset="UTF-8">

    <title>div橫向拖拽排序</title>

    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>

    <style type="text/css">

    body,div{

    padding: 0px;

    margin: 0px;

    }

    .box {

    margin-left: 15px;

    padding : 10px;

    padding-right: 0px;

    width : 810px;

    height : 150px;

    border : blue solid 1px;

    }

    .horizontal-div{

    float : left;

    margin-right: 10px;

    border: #000 solid 1px;

    text-align: center;

    width : 150px;

    height : 150px;

    }

    .horizontal-div-dash { 

    position: absolute; 

    width: 150px; 

    height: 150px; 

    margin-right: 10px; 

    border: 1px dashed blue; 

    background: #ececec; 

    opacity: 0.7; 

    .dash { 

    float : left; 

    width: 150px; 

    height: 150px; 

    margin-right: 10px; 

    border: 1px dashed #f00; 

    }; 

    </style>

    <script type="text/javascript">

      $(document).ready( function () { 

    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; choose = false; //拖拽對象 拖拽狀態(tài) 選中狀態(tài)

    var theDivId =0, theDivHeight = 0, theDivHalf = 0; tarFirstY = 0; //拖拽對象的索引、高度、的初始化。 

    var tarDiv = null, tarFirst, tempDiv; //要插入的目標(biāo)元素的對象, 臨時的虛線對象 

    var initPos = {x: 0, y: 0};

    $(".horizontal-div").each(function(){ 

      $(this).mousedown(function (event){ 

    choose = true;

      //拖拽對象 

      theDiv = $(this); 

      //記錄拖拽元素初始位置

      initPos.x = theDiv.offset().left;

      initPos.y = theDiv.offset().top;

      //鼠標(biāo)元素相對偏移量 

      range.x = event.pageX - theDiv.offset().left; 

      range.y = event.pageY - theDiv.offset().top; 

      theDivId = theDiv.index(); 

      theDivWidth = theDiv.width(); 

      theDivHalf = theDivWidth/2; 

      theDiv.attr("class","horizontal-div-dash"); 

      theDiv.css({left: initPos.x + 'px',top: initPos.y + 'px'}); 

       // 創(chuàng)建新元素 插入拖拽元素之前的位置(虛線框) 

      $("<div class='dash'></div>").insertBefore(theDiv); 

      tempDiv = $(".dash");

      });

        });

    $(document).mouseup(function(event) { 

    if(!choose){return false;}

      if(!move){

      theDiv.attr("class", "horizontal-div");

      tempDiv.remove(); // 刪除新建的虛線div

      choose = false;

       return false;

      }

    theDiv.insertBefore(tempDiv); // 拖拽元素插入到 虛線div的位置上 

    theDiv.attr("class", "horizontal-div"); //恢復(fù)對象的初始樣式 

    tempDiv.remove(); // 刪除新建的虛線div 

    move = false;

    choose = false;

      }).mousemove(function(event) { 

      if(!choose) return false;

      move = true;

    lastPos.x = event.pageX - range.x; 

    lastPos.y = event.pageY - range.y; 

    lastPos.x1 = lastPos.x + theDivWidth; 

    // 拖拽元素隨鼠標(biāo)移動 

    theDiv.css({left: lastPos.x + 'px',top: lastPos.y + 'px'}); 

    // 拖拽元素隨鼠標(biāo)移動 查找插入目標(biāo)元素 

    var $main = $('.horizontal-div'); // 局部變量:按照重新排列過的順序 再次獲取 各個元素的坐標(biāo), 

    $main.each(function () { 

      tarDiv = $(this); 

      tarPos.x = tarDiv.offset().left; 

      tarPos.y = tarDiv.offset().top; 

      tarPos.x1 = tarPos.x + tarDiv.width()/2; 

      tarFirst = $main.eq(0); // 獲得第一個元素 

      tarFirstX = tarFirst.offset().left + theDivHalf ; // 第一個元素對象的中心縱坐標(biāo) 

      //拖拽對象 移動到第一個位置 

      if (lastPos.x <= tarFirstX) { 

      tempDiv.insertBefore(tarFirst); 

      } 

      //判斷要插入目標(biāo)元素的 坐標(biāo)后, 直接插入 

      if (lastPos.x >= tarPos.x - theDivHalf && lastPos.x1 >= tarPos.x1 ) { 

      tempDiv.insertAfter(tarDiv); 

      } 

      }); 

      });

      });

    </script>

    </head>

    <body>

    <h1>div橫向拖拽排序</h1>

    <div class="box">

    <div class="horizontal-div" id="div1">div1</div>

    <div class="horizontal-div" id="div2">div2</div>

    <div class="horizontal-div" id="div3">div3</div>

    <div class="horizontal-div" id="div4">div4</div>

    <div class="horizontal-div" id="div5">div5</div>

     </div>

    </body>

    </html>

    以上這篇jQuery實(shí)現(xiàn)div橫向拖拽排序的簡單實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:jQuery實(shí)現(xiàn)div橫向拖拽排序的簡單實(shí)例
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機(jī)號
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)