xadhix
xadhix

Reputation: 174

How do I get the original position of "ui.draggable" in the "drop" event?

I drag a "draggable" object to a "droppable" object. I want to know if something is already there in the position. I have already done that (without jQuery UI).

  1. Can I do it somehow with jQuery UI?

  2. If there is an object already present, the dragged object must revert to the original position. How can I get the original position of ui.draggable inside the "drop" event?

Thanks.

Upvotes: 1

Views: 1118

Answers (2)

Sunil Marwaha
Sunil Marwaha

Reputation: 123

Look at the following, this may help

$(document).ready(function() {
    var x;
    var y;
    $("#div1").mousedown(function(e) {
        var pos = $(this).offset();
        x = e.pageX - pos.left;
        y = e.pageY - pos.top;
        //alert(x + "," + y);
        $("#drag").show().css({
            top: y,
            left: x
        });
        $("#drag").draggable();
    });
    $("#div1").mouseup(function(e) {
        var pos = $(this).offset();
        var a = e.pageX - pos.left;
        var b = e.pageY - pos.top;
        alert("Start-Top:" + y + "Start-Left" + x + "End-Top" + b + "End-Left" + a);
    });
});​

Upvotes: 0

Related Questions