使用 Google 托管的最新 jQuery/UI。我有以下标记:
<ul id="tree">
<li><a href="1/">One</a></li>
<li><a href="2/">Two</a></li>
</ul>
以及以下 javascript:
$(document).ready(function(){
// Droppable callbacks
function dragOver(overEvent, ui_object) {
$(this).mousemove(function(moveEvent){
console.log("moved over", this);
});
}
function drop_deactivate() {
$(this).unbind();
}
function drag_out() {
$(this).unbind();
}
// Actual dragging
$("#treeContainer li").draggable({
revert: true,
revertDuration: 0
});
// Actuall dropping
$("a").droppable({
tolerance: "pointer",
over: dragOver,
deactivate: drop_deactivate,
out: drag_out
});
});
如果我将第一个li
向下拖动到第二个上,则 mousemove 函数会触发(并且 firebug 会记录输出)。但是,如果我将第二个li
向上拖动到第一个上方,则 mousemove 函数不会触发。你可以在现场看到这个http://jsbin.com/ivala。是否有一个原因?我应该以其他方式捕获 mousemove 事件吗?
编辑:似乎认为 mousemove() 事件没有绑定到比当前被拖动的元素更早的元素(应该在鼠标悬停时绑定)。