3

I have an img element which is draggable. Now I want to trigger the drag() event manually like how do we trigger 'click' event as $(element).trigger('click'). Thanks.

Here is the function definition that I have

$('#imgToUpload').draggable({
        drag: function(event, ui) {
            if (ui.position.top > 0) {
                ui.position.top = 0;
            }
            var maxtop = ui.helper.parent().height() - ui.helper.height();
            if ( ui.position.top < maxtop) {
                ui.position.top = maxtop;
            }
            if ( ui.position.left > 0) {
                ui.position.left = 0;
            }
            var maxleft = ui.helper.parent().width() - ui.helper.width();
            if ( ui.position.left < maxleft) {
                ui.position.left = maxleft;
            }
            ImageCropping.calculateCroppedCoordinates();
        }
    });
John Britto
  • 457
  • 1
  • 4
  • 19

1 Answers1

5

Here is jquery ui plugin

https://github.com/jquery/jquery-ui/blob/9e8e339648901899827a58e5bf919f7dda03b88e/tests/jquery.simulate.js

include that on the page and then simply use

$("#myElement").simulate('drag');

pim
  • 12,019
  • 6
  • 66
  • 69