I am working on a mobile application where I am trying to combine jQuery UI draggable functions with jQuery Mobile taphold event. The idea is that the item becomes draggable when the chain is executed.
Draggable is initialized with elements in the following code:
$('div.rect', '#outerBox').draggable({ containment: "parent", grid: [50, 50], disabled: true, stop: function(event, ui) { $(this).draggable('disable'); $(this).removeClass('highlighted'); } });
As you can see, the drag and drop function is disabled initially because I want to enable it after the taphold event. For this, I am currently using the following code:
// Bind long press event to rectangle elements $('div.rect', '#outerBox').bind('taphold', function(event, ui) { // Enable dragging on long press $(this).addClass('highlighted'); $(this).draggable('enable'); });
This works, but the problem is that in order to drag an element around, it is necessary to intercept the "release-and-tap-again" event, and not to drag it directly after the taphold event. Maybe this is some kind of interference problem? I tried things like event.preventDefault()
, but my knowledge of jQuery events is not that much, so I have no idea if that really matters.
Any idea on how to solve this problem?
source share