2014-10-06 39 views
2

这个问题是关系到thisjQuery UI的排序 - 当用户开始从一个特定块

拖动的元素,我有两个块一个是“拖拽”,另一个是“排序”做一些事情。

我想要做的是当我开始拖动一个项目从“可排序”通过jQuery做些事情。

这是我的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(); 
} 
}); 

的问题是我之前从“拖动”到“sortableList”降元素,我想,当元素从“sortableList拖到做一些事情,做事情。 “

这是jsbin

有关我该怎么做的任何建议?

回答

1

我不确定这是否会算作jQuery UI Sortable中的错误 - 它看起来好像可能是。你可以得到它周围的一种方法是查询event参数start

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

Updated JSBin

+0

只是测试它,而不是工作... – agis 2014-10-06 13:07:01

+0

@agis以什么方式?当我特意开始拖动可排序的项目中的一个时,我只能看到警报。确保你已经打开JSBin上的“使用JS运行”按钮,如果它关闭自动运行 – 2014-10-06 13:08:11

+0

我的坏,现在它的工作。 – agis 2014-10-06 13:12:16