user1290426
user1290426

Reputation: 153

call function after dragging in jquery

I'm trying to call a function to check to position of a div after dragging it, but I am not sure how to make this work. I've written it out like this and a few other ways, but it either causes the whole thing not to work or the function isn't called:

$(".block").draggable(),function() { check(); };

Is there a simple way to make this work?

Upvotes: 3

Views: 3698

Answers (1)

VisioN
VisioN

Reputation: 145368

There is the event named stop. You can read about it here: http://jqueryui.com/demos/draggable/#event-stop.

The example code for getting position of the dragged element after stop dragging can be this:

$(".block").draggable({
    stop: function(event, ui) {
        var pos = ui.helper.position(); // just get pos.top and pos.left
    }
});

Check the working solution here: http://jsfiddle.net/rcmyy/

Upvotes: 8

Related Questions