Call function after drag and drop in jquery

I am trying to call a function to check the position of a div after dragging it, but I'm not sure how to do it. I wrote this in several other ways, but it either makes everything not work, or the function is not called:

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

Is there an easy way to make this work?

+3
source share
1 answer

There is an event with a name stop. You can read about it here: http://jqueryui.com/demos/draggable/#event-stop .

An example code for getting the position of a dragged item after dragging a foot can be as follows:

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

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

+6
source

All Articles