jquery ui sortable disable for one li item

前端 未结 4 1285
走了就别回头了
走了就别回头了 2020-12-16 09:51

It is possible do disable jquery ui sortable just for one list item? Here is the code example:

  • Item 1
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 09:53

    This question has two similar answers... but their behavior is very different.

    Using cancel, you can make item sortable / not-sortable dynamically:

    $(".sortable_cancel").sortable({ 
        cancel: ".unsortable" 
    });
    

    Using items, you can make item sortable / not-sortable but only at initialization time:

    $(".sortable_item").sortable({
        items: "li:not(.unsortable)"
    });
    

    See the difference in this demo:

    $(".sortable_cancel").sortable({
        cancel: ".unsortable"
    });
     $(".sortable_cancel").disableSelection();
     
      $(".sortable_item").sortable({
          items: "li:not(.unsortable)"
        });
     $(".sortable_item").disableSelection();
    .sortable {
        list-style-type: none;
        width: 60%;
        padding: 5px;
    }
    
    .sortable li {
      padding-left: 1.5em;
    }
    
    li.unsortable {
        background: #999;
        opacity:.5;
    }
    
    
    
    • Item1
    • Item2
    • Item3
    • Item4
    • Item5
    • Item1
    • Item2
    • Item3
    • Item4
    • Item5

提交回复
热议问题