jquery.ui.sortable

官方API地址:http://jqueryui.com/demos/sortable/jquery

 

全部的事件回調函數都有兩個參數:event和ui,瀏覽器自有event對象,和通過封裝的ui對象   
ui.helper - 表示sortable元素的JQuery對象,一般是當前元素的克隆對象   
ui.position - 表示相對當前對象,鼠標的座標值對象{top,left}   
ui.offset - 表示相對於當前頁面,鼠標的座標值對象{top,left}   
ui.item - 表示當前拖拽的元素   
ui.placeholder - 佔位符(若是有定義的話)   
ui.sender - 當前拖拽元素的所屬sortable對象(僅當元素是從另外一個sortable對象傳遞過來時有用)   

·參數(參數名 : 參數類型 : 默認值)   
appendTo : String : 'parent' 
Defines where the helper that moves with the mouse is being appended to during the drag (for example, to resolve overlap/zIndex issues).   
初始:$('.selector').sortable({ appendTo: 'body' });   
獲取:var appendTo = $('.selector').sortable('option', 'appendTo');   
設置:$('.selector').sortable('option', 'appendTo', 'body');   

axis : String : false    
若是有設置,則元素僅能橫向或縱向拖動。可選值:'x', 'y' 
初始:$('.selector').sortable({ axis: 'x' });   
獲取:var axis = $('.selector').sortable('option', 'axis');   
設置:$('.selector').sortable('option', 'axis', 'x');   

cancel : Selector : ':input,button'    
阻止排序動做在匹配的元素上發生。   
初始:$('.selector').sortable({ cancel: 'button' });   
獲取:var cancel = $('.selector').sortable('option', 'cancel');   
設置:$('.selector').sortable('option', 'cancel', 'button');   

connectWith : Selector : false    
容許sortable對象鏈接另外一個sortable對象,可將item元素拖拽到另外一箇中。   
初始:$('.selector').sortable({ connectWith: '.otherlist' });   
獲取:var connectWith = $('.selector').sortable('option', 'connectWith');   
設置:$('.selector').sortable('option', 'connectWith', '.otherlist');   

containment : Element, String, Selector : false    
約束排序動做只能在一個指定的範圍內發生。可選值:DOM對象, 'parent', 'document', 'window', 或jQuery對象   
初始:$('.selector').sortable({ containment: 'parent' });   
獲取:var containment = $('.selector').sortable('option', 'containment');   
設置:$('.selector').sortable('option', 'containment', 'parent');   

cursor : String : 'auto' 
定義在開始排序動做時,若是的樣式。   
初始:$('.selector').sortable({ cursor: 'crosshair' });   
獲取:var cursor = $('.selector').sortable('option', 'cursor');   
設置:$('.selector').sortable('option', 'cursor', 'crosshair');   

cursorAt : Object : false    
當開始移動時,鼠標定位在的某個位置上(最多兩個方向)。可選值:{ top, left, right, bottom }.   
初始:$('.selector').sortable({ cursorAt: 'top' });   
獲取:var cursorAt = $('.selector').sortable('option', 'cursorAt');   
設置:$('.selector').sortable('option', 'cursorAt', 'top');   

delay : Integer : 0   
以毫秒爲單位,設置延遲多久才激活排序動做。此參數可防止誤點擊。   
初始:$('.selector').sortable({ delay: 500 });   
獲取:var delay = $('.selector').sortable('option', 'delay');   
設置:$('.selector').sortable('option', 'delay', 500);   

distance : Integer : 1   
決定至少要在元素上面拖動多少像素後,才正式觸發排序動做。   
初始:$('.selector').sortable({ distance: 30 });   
獲取:var distance = $('.selector').sortable('option', 'distance');   
設置:$('.selector').sortable('option', 'distance', 30);   

dropOnEmpty : Boolean : true    
是否允許拖拽到一個空的sortable對象中。   
初始:$('.selector').sortable({ dropOnEmpty: false });   
獲取:var dropOnEmpty = $('.selector').sortable('option', 'dropOnEmpty');   
設置:$('.selector').sortable('option', 'dropOnEmpty', false);   

forceHelperSize : Boolean : false    
If true, forces the helper to have a size.   
初始:$('.selector').sortable({ forceHelperSize: true });   
獲取:var forceHelperSize = $('.selector').sortable('option', 'forceHelperSize');   
設置:$('.selector').sortable('option', 'forceHelperSize', true);   

forcePlaceholderSize : Boolean : false 
If true, forces the placeholder to have a size.   
初始:$('.selector').sortable({ forcePlaceholderSize: true });   
獲取:var forcePlaceholderSize = $('.selector').sortable('option', 'forcePlaceholderSize');   
設置:$('.selector').sortable('option', 'forcePlaceholderSize', true);   

grid : Array : false    
將排序對象的item元素視爲一個格子處理,每次移動都按一個格子大小移動,數組值:[x,y]   
初始:$('.selector').sortable({ grid: [50, 20] });   
獲取:var grid = $('.selector').sortable('option', 'grid');   
設置:$('.selector').sortable('option', 'grid', [50, 20]);   

handle : Selector, Element : false    
限制排序的動做只能在item元素中的某個元素開始。   
初始:$('.selector').sortable({ handle: 'h2' });   
獲取:var handle = $('.selector').sortable('option', 'handle');   
設置:$('.selector').sortable('option', 'handle', 'h2');   

helper : String, Function : 'original'    
設置是否在拖拽元素時,顯示一個輔助的元素。可選值:'original', 'clone' 
初始:$('.selector').sortable({ helper: 'clone' });   
獲取:var helper = $('.selector').sortable('option', 'helper');   
設置:$('.selector').sortable('option', 'helper', 'clone');   

items : Selector : '> *'    
指定在排序對象中,哪些元素是能夠進行拖拽排序的。   
初始:$('.selector').sortable({ items: 'li' });   
獲取:var items = $('.selector').sortable('option', 'items');   
設置:$('.selector').sortable('option', 'items', 'li');   

opacity : Float : false    
定義當排序時,輔助元素(helper)顯示的透明度。   
初始:$('.selector').sortable({ opacity: 0.6 });   
獲取:var opacity = $('.selector').sortable('option', 'opacity');   
設置:$('.selector').sortable('option', 'opacity', 0.6);   

placeholderType: StringDefault: false    
設置當排序動做發生時,空白佔位符的CSS樣式。   
初始:$('.selector').sortable({ placeholder: 'ui-state-highlight' });   
獲取:var placeholder = $('.selector').sortable('option', 'placeholder');   
設置:$('.selector').sortable('option', 'placeholder', 'ui-state-highlight');   

revert : Boolean : false 
若是設置成true,則被拖拽的元素在返回新位置時,會有一個動畫效果。   
初始:$('.selector').sortable({ revert: true });   
獲取:var revert = $('.selector').sortable('option', 'revert');   
設置:$('.selector').sortable('option', 'revert', true);   

scroll : Boolean : true 
若是設置成true,則元素被拖動到頁面邊緣時,會自動滾動。   
初始:$('.selector').sortable({ scroll: false });   
獲取:var scroll = $('.selector').sortable('option', 'scroll');   
設置:$('.selector').sortable('option', 'scroll', false);   

scrollSensitivity : Integer : 20    
設置當元素移動至邊緣多少像素時,便開始滾動頁面。   
初始:$('.selector').sortable({ scrollSensitivity: 40 });   
獲取:var scrollSensitivity = $('.selector').sortable('option', 'scrollSensitivity');   
設置:$('.selector').sortable('option', 'scrollSensitivity', 40);   

scrollSpeed : Integer : 20   
設置頁面滾動的速度。   
初始:$('.selector').sortable({ scrollSpeed: 40 });   
獲取:var scrollSpeed = $('.selector').sortable('option', 'scrollSpeed');   
設置:$('.selector').sortable('option', 'scrollSpeed', 40);   

tolerance : String : 'intersect' 
設置當拖動元素越過其它元素多少時便對元素進行從新排序。可選值:'intersect', 'pointer' 
intersect:至少重疊50%   
pointer:鼠標指針重疊元素   
初始:$('.selector').sortable({ tolerance: 'pointer' });   
獲取:var tolerance = $('.selector').sortable('option', 'tolerance');   
設置:$('.selector').sortable('option', 'tolerance', 'pointer');   

zIndex : Integer : 1000   
設置在排序動做發生時,元素的z-index值。   
初始:$('.selector').sortable({ zIndex: 5 });   
獲取:var zIndex = $('.selector').sortable('option', 'zIndex');   
設置:$('.selector').sortable('option', 'zIndex', 5);   


·事件   

start   
當排序動做開始時觸發此事件。   
定義:$('.selector').sortable({ start: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortstart', function(event, ui) { ... });   

sort   
當元素髮生排序時觸發此事件。   
定義:$('.selector').sortable({ sort: function(event, ui) { ... } });   
綁定:$('.selector').bind('sort', function(event, ui) { ... });   

change   
當元素髮生排序且座標已發生改變時觸發此事件。   
定義:$('.selector').sortable({ change: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortchange', function(event, ui) { ... });   

beforeStop   
當排序動做結束以前觸發此事件。此時佔位符元素和輔助元素仍有效。   
定義:$('.selector').sortable({ beforeStop: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortbeforeStop', function(event, ui) { ... });   

stop   
當排序動做結束時觸發此事件。   
定義:$('.selector').sortable({ stop: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortstop', function(event, ui) { ... });   

update   
當排序動做結束時且元素座標已經發生改變時觸發此事件。   
定義:$('.selector').sortable({ update: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortupdate', function(event, ui) { ... });   

receive   
當一個已鏈接的sortable對象接收到另外一個sortable對象的元素後觸發此事件。   
定義:$('.selector').sortable({ receive: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortreceive', function(event, ui) { ... });   

over   
當一個元素拖拽移入另外一個sortable對象後觸發此事件。   
定義:$('.selector').sortable({ over: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortover', function(event, ui) { ... });   

out   
當一個元素拖拽移出sortable對象移出並進入另外一個sortable對象後觸發此事件。   
定義:$('.selector').sortable({ out: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortout', function(event, ui) { ... });   

activate   
當一個有使用鏈接的sortable對象開始排序動做時,全部容許的sortable觸發此事件。   
定義:$('.selector').sortable({ activate: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortactivate', function(event, ui) { ... });   

deactivate   
當一個有使用鏈接的sortable對象結束排序動做時,全部容許的sortable觸發此事件。   
定義:$('.selector').sortable({ deactivate: function(event, ui) { ... } });   
綁定:$('.selector').bind('sortdeactivate', function(event, ui) { ... });   


·方法   
destory   
從元素中移除拖拽功能。   
用法:.sortable( 'destroy' )   

disable   
禁用元素的拖拽功能。   
用法:.sortable( 'disable' )   

enable   
啓用元素的拖拽功能。   
用法:.sortable( 'enable' )   

option   
獲取或設置元素的參數。   
用法:.sortable( 'option' , optionName , [value] )   

serialize   
獲取或設置序列化後的每一個item元素的id屬性。   
用法:.sortable( 'serialize' , [options] )   

toArray   
獲取序列化後的每一個item元素的id屬性的數組。   
用法:.sortable( 'toArray' )   

refresh   
手動從新刷新當前sortable對象的item元素的排序。   
用法:.sortable( 'refresh' )   

refreshPositions   
手動從新刷新當前sortable對象的item元素的座標,此方法可能會下降性能。   
用法:.sortable( 'refreshPositions' )   

cancel   
取消當前sortable對象中item元素的排序改變。   
用法:.sortable( 'cancel' )數組

原文地址:http://hb-keepmoving.iteye.com/blog/1154618瀏覽器

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息