编辑或拖动相同的单击

时间:2014-01-11 21:14:22

标签: javascript jquery html jquery-ui drag-and-drop

我想要这个:我可以点击或拖动一个div。如果我点击,我可以立即编辑它(插件使其可编辑)。或者,如果我做了一个mousedown-mousemove事件,它就会拖延。

MY JSFIDDLE:

这是我的代码:http://jsfiddle.net/9N2hh/

这里的问题是,第一次一切正常。但即使重新绑定函数,第二次它也不起作用。

有谁知道如何解决这个问题?

编辑: 我需要代码是这样的:

obj.on('mousedown', function(){
    obj.on('mousemove')..  //here the drag should fire
    obj.on('mouseup') ..  //here the edit should fire (which fires without anything because "draggable: disabled" so just the mousemove need to be edited.
})

1 个答案:

答案 0 :(得分:0)

这是你想要的吗?

http://jsfiddle.net/9N2hh/7/

obj.on('mousemove', function() {
    // Do stuff while moving.
});

obj.on('mouseout', function() {
    // sets draggable false
});

我正在使用mouseout事件来重置draggable属性。我也移动了鼠标移动绑定,因此在每次调用mousedown时都没有反弹。

当我修改你的代码时,我想知道悬停事件是否更合适?这表示可以拖动您的元素。鼠标悬停和mousedown时你似乎允许拖动,这是draggable的默认状态行为。

如果您确实需要在其他事件中附加事件,则需要检查事件是否已附加。使用此链接How to check if an event handler exist using jQuery or JS?是某人做类似的事情