jQuery Easy UI Draggable(拖動)組件,jquerydraggable

來源:互聯網
上載者:User

jQuery Easy UI Draggable(拖動)組件,jquerydraggable

上文已經提到過了 jQuery EasyUI外掛程式引用一般我們常用的有兩種方式(排除easyload載入方式),所以本篇要總結的Draggable組件同樣有兩種方式載入:

(1)、使用class載入方式:

<div id="box" class="easyui-draggable" style="width:400px;height:200px;background:red;">
內容部分
</div>

(2)、JS 載入調用

$('#box').draggable();

同樣上文也說了,使用class屬性不利於我們拓展組件的其他屬性,所以我們使用JS調用的方式,後面的文章也是使用JS調用的方式。

該組件有若干屬性、方法及觸發事件,不在這裡列舉了,都放到程式碼範例裡並且加上注釋了。

樣本:

<!DOCTYPE html><html><head><title>jQuery Easy UI</title><meta charset="UTF-8" /><script type="text/javascript" src="easyui/jquery.min.js"></script><script type="text/javascript" src="easyui/jquery.easyui.min.js"></script><script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js" ></script><link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css" /><link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" /><script>$(function () {$.fn.draggable.defaults.cursor = 'text';//*****採用這種方式重寫預設值$('#box').draggable({//revert : true,  預設值為false  設定為true的時候拖動結束後返回起始位置//cursor : 'text',定義拖動時指標的樣式//handle : '#pox',開始拖動時的控制代碼,就是點擊哪裡可以拖動,參數是一個JQ選取器//disabled : true,  設定為true的時候,禁止拖動//edge : 0,//axis : 'v',不寫:任意拖動  值為v:垂直拖動   值為h:水平拖動//proxy : 'clone',當使用'clone'的時候則複製一個替代元素拖動,如果指定一個函數,則可以自訂替代元素。deltaX : 50,//被拖動元素對應於當前游標位置XdeltaY : 50,//被拖動元素對應於當前游標位置Yproxy : function (source) {var p = $('<div style="width:400px;height:200px;border:1px dashed #ccc">');p.html($(source).html()).appendTo('body');return p;}/**可觸發的事件:onBeforeDrag : function (e) {alert('拖動前觸發!');},onBeforeDrag : function (e) {//return false;},onStartDrag : function (e) {alert('拖動開始觸發!');console.log($('#box').draggable('proxy'));},onDrag : function (e) {//alert('拖動過程觸發!');},onStopDrag : function (e) {alert('拖動結束後觸發!');}*/});//$('#box').draggable('disable');//禁止拖動//$('#box').draggable('enable');//可以拖動//alert($('#box').draggable('options'));//返回對象屬性});</script></head><body><div id="box" style="width:400px;height:200px;background:orange;"><span id="pox">內容部分</span></div></body></html>

點擊下載原始碼


跪一熟悉jquery-ui-1820customminjs的jquery ui的jquery,怎設定元素對象禁用拖動draggable

你可以把這行代碼寫在它的建構函式裡,也就是一產生就不允許拖動
 
jQuery UI 的拖拽範圍問題

可以在開始的時候設定containment。
$(function() {
$( "#draggable5" ).draggable({
'containment':[x1,y1,x2,y2]
});
});

x1,y1,x2,y2變化的時候調用
$( "#draggable5" ).draggable("option", "containment", [x1,y1,x2,y2]);
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.