詳解有關(guān)easyUI的拖動(dòng)操作中droppable,draggable用法例子
這個(gè)demo展示的效果為:從上面可以拖動(dòng)到下面相應(yīng)的框中(原有的不能再拖動(dòng)),拖動(dòng)框中的東西到外面可以取消
-----------以下為HTML
<!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>品類(lèi)</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>單價(jià)</span> </li> </ul> <div class="target"> <div class="target-cascade"> <span>級(jí)聯(lián)統(tǒng)計(jì)指標(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 }); // 級(jí)聯(lián)統(tǒng)計(jì)指標(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){ // 判斷拖動(dòng)的元素是否存在于放置區(qū)內(nèi) if($(source).draggable('options').proxy === 'clone'){ // 禁用拖動(dòng) NotDrag(source); // 將拖入元素的原位置記錄下來(lái) var buttonName = $(source).find('span').html(); console.log("--------"+$(source).index()); tab[buttonName] = $(source).index();//返回指定元素相對(duì)于其他元素的位置(0,1等),如果沒(méi)有找到,則返回-1 var Ele = $('<li class='+ $(source)[0].className +'><button>'+ buttonName +'</button></li>'); Ele.appendTo('.target-cascade ul'); } $(this).css('border','1px solid black'); // 拖動(dòng)放置區(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){ // 判斷拖動(dòng)的元素是否存在于放置區(qū)內(nèi) if($(source).draggable('options').proxy === 'clone'){ // 禁用拖動(dòng) 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">計(jì)數(shù)</option></select></li>'); Ele.appendTo('.target-column ul'); } $(this).css('border','1px solid black'); // 拖動(dòng)放置區(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(); } }); } }); //禁止拖動(dòng) function NotDrag(source){ $(source).draggable('disable');//禁用拖動(dòng)動(dòng)作 $(source).find('i').css('backgroundColor','grey'); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實(shí)現(xiàn)的仿百度,仿谷歌搜索下拉框效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的仿百度,仿谷歌搜索下拉框效果,結(jié)合實(shí)例形式分析了基于jQuery的鼠標(biāo)事件響應(yīng)與頁(yè)面元素動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-12-12jQuery原理系列-css選擇器的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)?lái)一篇jQuery原理系列-css選擇器的簡(jiǎn)單實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06jQuery中animate()的使用方法及解決$(”body“).animate({“scrollTop”:top})
這篇文章主要介紹了關(guān)于jQuery中animate()的使用方法及解決$("body").animate({"scrollTop":top})不被Firefox支持的問(wèn)題,文中介紹的非常詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-04-04jquery實(shí)現(xiàn)像柵欄一樣左右滑出式二級(jí)菜單效果代碼
這篇文章主要介紹了jquery實(shí)現(xiàn)像柵欄一樣左右滑出式二級(jí)菜單效果代碼,涉及jquery鼠標(biāo)click點(diǎn)擊事件及頁(yè)面元素動(dòng)態(tài)操作的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08jQuery獲取iframe的document對(duì)象的方法
獲取iframe的document對(duì)象進(jìn)行dom的操作,實(shí)現(xiàn)方法很多,下面是jquery的實(shí)現(xiàn)過(guò)程,喜歡玩iframe的朋友可以參考下2014-10-10jQuery列表拖動(dòng)排列具體實(shí)現(xiàn)
列表拖動(dòng)排列的實(shí)現(xiàn)方法有很多,下文為大家介紹下使用jQuery是如何實(shí)現(xiàn)的,感興趣的朋友不要錯(cuò)過(guò)2013-11-11jQuery實(shí)現(xiàn)移動(dòng)端滑塊拖動(dòng)選擇數(shù)字效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)移動(dòng)端滑塊拖動(dòng)選擇數(shù)字效果,jQuery實(shí)現(xiàn)移動(dòng)端滑塊拖動(dòng)效果,感興趣的小伙伴們可以參考一下2015-12-12