easyui Droppable組件實現放置特效_jquery

來源:互聯網
上載者:User

所謂放置,就是將一個物體放入一個物體內,當然對於easyui來說觸發各種效果是必不可少的,同時這個組件也不會依賴於其他組件。

  Droppable的載入方式

  1,class  載入   一直不太喜歡class方式的載入  浪費一個位置,代碼一多還看著亂七八糟的。

複製代碼 代碼如下:
<div id='dd' class="easyui-droppable" data-options="accept:'#box,#pox'"></div>

  2,js 載入調用

$("#box").droppable({  accept:'#pox',     //將元素pox 放置在元素box中});   

  Droppable的屬性

    1,accept     預設為null,確定哪些元素被接受,也就是那個元素能被放置

$("#box").droppable({  accept:'#pox',     //將元素pox 放置在元素box中});  

    2,deisabled  預設為false   如果為true,則禁止放置

$("#box").droppable({  accept:'#pox',     //將元素pox 放置在元素box中  disabled : true ,    //禁止放置});

  Droppable 事件列表

  1,onDragEnter  在被拖拽元素到放置地區內的時候觸發

  2,onDragOver 在被拖拽元素經過放置地區的時候觸發

  3,onDragLeave  在被拖拽元素離開放置地區的時候觸發

  4,onDrop  在被拖拽元素放入到放置區的時候觸發

 onDragEnter /onDragOver/onDragLeave/onDrop: function (e,source){   //source 參數擷取DOM元素 }

  Droppable 方法列表

  1,options 返回屬性對象

console.log($('#box').droppable('options'));

  2,enable,disable 和上面屬性的功能是一樣的  分別是啟用和禁止放置

$('#box').droppable('enable/disable')

給大家展示下官方的樣本吧

<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Accept a Drop - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.6/themes/metro/easyui.css"> <link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.6/themes/icon.css"> <link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.6/demo/demo.css"> <script type="text/javascript" src="jquery-easyui-1.3.6/jquery.min.js"></script> <script type="text/javascript" src="jquery-easyui-1.3.6/jquery.easyui.min.js"></script></head><body> <div style="margin:20px 0;"></div> <div id="source" style="border:1px solid #ccc;width:300px;height:400px;float:left;margin:5px;">  drag me!  <div id="d1" class="drag">Drag 1</div>  <div id="d2" class="drag">Drag 2</div>  <div id="d3" class="drag">Drag 3</div> </div>  <div id="target" style="border:1px solid #ccc;width:300px;height:400px;float:left;margin:5px;">  drop here! </div> <div style="clear:both"></div> <style type="text/css">  .drag{   width:100px;   height:50px;   padding:10px;   margin:5px;   border:1px solid #ccc;   background:#AACCFF;  }  .dp{   opacity:0.5;   filter:alpha(opacity=50);  }  .over{   background:#FBEC88;  } </style> <script>  /**  使用js方式將元素設定為可draggable的  */  $(function(){   $('.drag').draggable({    proxy:'clone',    revert:true,    cursor:'pointer',    onStartDrag:function(){     $(this).draggable('options').cursor='not-allowed';//設定滑鼠樣式為不可拖動     $(this).draggable('proxy').addClass('dp');//設定樣式    },    onStopDrag:function(){     $(this).draggable('options').cursor='auto';//設定滑鼠    }   });   //將容易置為droppable並且可接受元素   $('#target').droppable({    accept:'#d1,#d3',    onDragEnter:function(e,source){//拖入     $(source).draggable('options').cursor='auto';     $(source).draggable('proxy').css('border','1px solid red');     $(this).addClass('over');    },    onDragLeave:function(e,source){//脫離     $(source).draggable('options').cursor='not-allowed';     $(source).draggable('proxy').css('border','1px solid #ccc');     $(this).removeClass('over');    },    onDrop:function(e,source){//放下     $(this).append(source)     $(this).removeClass('over');     alert("我被放下了");    } ,    //onDropOver當元素被拖出(成功放入到某個容器)的時候觸發    onDragOver:function(e,source){      alert("我被拖出去了");//先於alert("我被放下了");執行,表明其觸發在onDrop之前。   }   });  }); </script> </body></html>

          運行效果圖這裡就不給出了,官網直接就可以查看。OVER!

          效果地址: http://www.jeasyui.com/demo/main/index.php?plugin=Droppable&theme=default&dir=ltr&pitem=

easyui 1.3.5 Droppable 就此完結。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.