您好,登錄后才能下訂單哦!
這篇文章主要介紹easyUI中draggable怎么用,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
示例:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <link rel="stylesheet" type="text/css" href="css/bootstrap-3.3.5/css/bootstrap.min.css" rel="external nofollow" > <link rel="stylesheet" type="text/css" href="css/easyui.css" rel="external nofollow" > <link rel="stylesheet" type="text/css" href="css/icon.css" rel="external nofollow" > <link rel="stylesheet" href="css/demo.css" rel="external nofollow" > </head> <body> <div class="container"> <ul class="items"> <li class="category"> <i></i> <span>品類</span> </li> <li class="factory"> <i></i> <span>工廠</span> </li> <li class="with-high"> <i></i> <span>跟高</span> </li> <li class="with-type"> <i></i> <span>跟型</span> </li> <li class="price"> <i></i> <span>單價</span> </li> </ul> <div class="target"> <div class="target-cascade"> <span>級聯(lián)統(tǒng)計指標(biāo)</span> <ul> </ul> </div> <div class="target-column"> <span>列指標(biāo)</span> <ul> </ul> </div> </div> </div> <script src="js/jquery.js"></script> <script src="js/jquery.easyui.min.js"></script> <script src="js/demo.js"></script> </body> </html>
-------------以下為js代碼
var tab = []; $('.items li').draggable({ proxy: 'clone', revert: true }); // 級聯(lián)統(tǒng)計指標(biāo)放置區(qū) $('.target-cascade').droppable({ onDragEnter: function(e,source){ $(this).css('border','1px solid red'); }, onDragLeave: function(e,source){ $(this).css('border','1px solid black'); }, onDrop: function(e,source){ // 判斷拖動的元素是否存在于放置區(qū)內(nèi) if($(source).draggable('options').proxy === 'clone'){ // 禁用拖動 NotDrag(source); // 將拖入元素的原位置記錄下來 var buttonName = $(source).find('span').html(); console.log("--------"+$(source).index()); tab[buttonName] = $(source).index();//返回指定元素相對于其他元素的位置(0,1等),如果沒有找到,則返回-1 var Ele = $('<li class='+ $(source)[0].className +'><button>'+ buttonName +'</button></li>'); Ele.appendTo('.target-cascade ul'); } $(this).css('border','1px solid black'); // 拖動放置區(qū)內(nèi)的元素 $(this).find('button').draggable({ revert: true, onStopDrag: function(e){ var _index = tab[$(this).html()]; $(this).parent().remove(); $('.items li:eq('+_index+')').draggable('enable'); $('.items li:eq('+_index+')').find('i').css('backgroundColor','red'); } }); } }); // 列指標(biāo)放置區(qū) $('.target-column').droppable({ onDragEnter: function(e,source){ $(this).css('border','1px solid red'); }, onDragLeave: function(e,source){ $(this).css('border','1px solid black'); }, onDrop: function(e,source){ // 判斷拖動的元素是否存在于放置區(qū)內(nèi) if($(source).draggable('options').proxy === 'clone'){ // 禁用拖動 NotDrag(source); var buttonName = $(source).find('span').html(); tab[buttonName] = $(source).index(); var Ele = $('<li class='+ $(source)[0].className +'><button>'+ buttonName +'</button><select><option value ="show">顯示</option>'+ '<option value ="sum">求和</option><option value ="count">計數(shù)</option></select></li>'); Ele.appendTo('.target-column ul'); } $(this).css('border','1px solid black'); // 拖動放置區(qū)內(nèi)的元素 $(this).find('button').draggable({ revert: true, onDrag: function(e){ $(e.data.parent).find('select').hide(); }, onStopDrag: function(e){ var _index = tab[$(this).html()]; $(this).parent().remove(); $('.items li:eq('+_index+')').draggable('enable'); $('.items li:eq('+_index+')').find('i').css('backgroundColor','red'); $(e.target).siblings('select').show(); } }); } }); //禁止拖動 function NotDrag(source){ $(source).draggable('disable');//禁用拖動動作 $(source).find('i').css('backgroundColor','grey'); }
以上是“easyUI中draggable怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。