Wolf and Dom solutions work perfectly and are the basis for my solution, but you mentioned that you are using jquery ui draggable , so this is a possible solution using a jquery ui draggable object in combination with droppable . I am trying to trigger droppable events when draggable drag and drop them and throw them at them, so I used the built-in / private functions of the ui.mouse object, which draggable inherits and overrides.
$(document).ready(function(){ var click = false $(document).bind('mousemove', function (e) { if (click == true) { $('#drag').data('uiDraggable')._mouseDrag(e); } }); $('#drag').draggable().click(function(e) { if(!click){ $(this).data('uiDraggable')._mouseCapture(e, true) $(this).data('uiDraggable')._mouseStart(e, true, true); }else{ $(this).data('uiDraggable')._mouseUp(e); $(this).data('uiDraggable')._mouseStop(e); } click = !click; return false; }); $('html').click(function() { click = false; }); });
Heres a fiddle . To see the dropdown stuff, just uncomment the dropdown stuff in js.
Note: this is a solution for the current version of jQuery ui (1.9.2), but may change in future versions as it uses private calls.
Todd bluhm
source share