1

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.

Toribio
  • 3,963
  • 3
  • 34
  • 48
xadhix
  • 174
  • 15

2 Answers2

1

You can find answer from previous post Draggable revert if outside this div and inside of other draggables (using both invalid and valid revert options)

Demo is here http://jsfiddle.net/htWV3/1/

Community
  • 1
  • 1
Miki Shah
  • 815
  • 9
  • 20
0

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);
    });
});​
code-jaff
  • 9,230
  • 4
  • 35
  • 56