jQuery UI sortable - do something when user starts dragging an element from a specific block

拟墨画扇 提交于 2020-01-04 09:25:14

问题


This question is related to this

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.

this is my JS:

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

 $("#sidebar-wrapper").droppable({
 accept: 'li',
 drop: function (event, ui) {
     ui.helper.remove();
 }
 });

The problem is that is doing something before I drop the element from "draggable" to "sortableList" and I want to do something when element is dragged from "sortableList."

Here's a jsbin.

Any suggestions on how can I do this?


回答1:


I'm not sure if this would count as a bug in the jQuery UI Sortable or not - it certainly seems that it might be. One way you can get around it is to query the event parameter in start:

$(".sortableList").sortable({
    start: function(event, ui) {
        if (event.handleObj.namespace=="sortable")
            alert("Do something here!");
    }
});

Updated JSBin



来源:https://stackoverflow.com/questions/26216281/jquery-ui-sortable-do-something-when-user-starts-dragging-an-element-from-a-sp

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