问题
I am trying to drag an element without keeping the mouse button down.
The behavior I would like is :
- I click on a draggable item
- Drag my item without keeping mouse left click down : just follow the mouse as a cursor
- I click on a droppable container to confirm and append my item
I am able to simulate this behavior if I add an alert
box durring the start event.
start : function(){
alert('test')
},
Here is the fiddle : http://jsfiddle.net/QvRjL/103/
How is it possible to code this behavior without the alert box?
回答1:
Here is a good solution about this problem : Trigger Click-and-Hold Event
http://jsfiddle.net/VXbpu/1/
http://jsfiddle.net/vPruR/70/
var click = false;
$(document).bind('mousemove', function (e) {
if (click == true) {
$('#your_div_id').css({
left: e.pageX,
top: e.pageY
});
}
});
$('#your_div_id').click(function() {
click = !click;
return false;
});
$('html').click(function() {
click = false;
});
来源:https://stackoverflow.com/questions/13518371/jquery-ui-drag-element-without-keeping-mouse-button-down-follow-the-cursor