jQuery 排序插件:html5sortable

jopen 10年前發布 | 29K 次閱讀 jQuery Ajax框架 html5sortable

HTML5 Sortable 是一個 jQuery 插件,使用本地拖拽 API 來創建可排序的列表和網格。

特性:

  • 小于 1KB (簡化和壓縮 )

  • 使用本地的拖拽 API

  • 支持列表和網格風格的布局

  • 類似 jQuery-UI 可排序插件的 API 和功能

  • 可以在 IE 5.5+, Firefox 3.5+, Chrome 3+, Safari 3+ 和 Opera 12+ 上使用

用法:

從這里下載 here,然后:

<ul class="sortable">
    <li>Item 1
    <li>Item 2
    <li>Item 3
    <li>Item 4
</ul>
<script src="jquery.sortable.js"></script>
<script>
    $('.sortable').sortable();
</script>

Use .sortable-dragging and .sortable-placeholder selectors to change the styles of a dragging item and its placeholder respectively.

Use sortupdate event if you want to do something when the order changes (e.g. storing the new order):

$('.sortable').sortable().bind('sortupdate', function() {            //Triggered when the user stopped sorting and the DOM position has changed. 
});

Use items option to specifiy which items inside the element should be sortable.

$('.sortable').sortable({
    items: ':not(.disabled)' });

Use handle option to create sortable lists with handles:

$('.sortable').sortable({
    handle: '.handle' });

Use connectWith option to create connected lists:

$('#sortable1, #sortable2').sortable({
    connectWith: '.connected' });

To remove the sortable functionality completely:

$('.sortable').sortable('destroy');

To disable the sortable temporarily:

$('.sortable').sortable('disable');

To enable a disabled sortable:

$('.sortable').sortable('enable');

The API is compatible with jquery-ui. So you can use jquery-ui as a polyfill in older browsers:

yepnope({
    test: Modernizr.draganddrop,
    yep: 'jquery.sortable.js',
    nope: 'jquery-ui.min.js',
    complete: function() {              
        $('.sortable').sortable().bind('sortupdate', function() {                           
                //Store the new order.             
    }
    }
});

項目主頁:http://www.baiduhome.net/lib/view/home/1387940465765

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!