jQuery UI sortable - do something when item is dragged

人走茶凉 提交于 2019-12-31 06:52:06

问题


I have two block one is "draggable" and the other is "sortable".

What I want to do is when I start dragging an item from "sortable" to do something via jQuery.

Here's my JS:

 $(".sortableList").sortable({

 });
 $(".draggable").draggable({
  connectToSortable: '.sortableList',
  cursor: 'pointer',
  helper: 'clone',
  revert: 'invalid',
  start: function (event, ui) {
     $(this).addClass('testing');
 }
 });

Here's a jsbin

Any ideas how can I do this?


回答1:


You have to add update event at sortable like this :

     $(".sortableList").sortable({ 
            update: function(event, ui) {
               //alert("Do something here when item left!");
            },
            start: function(event, ui) {
               //alert("Do something here when item just dragged from sortable!");
        },
     });

So when the dragged from sortable is left to the position update event will trigger and when it dragged .start is triggered.



来源:https://stackoverflow.com/questions/26192255/jquery-ui-sortable-do-something-when-item-is-dragged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!