user1184100
user1184100

Reputation: 6894

Not able to place the dragged element relative to the div - jquery

Here's the code http://jsfiddle.net/DTYEB/ after dropping the element into the dropbox if I put below code, I want the element to be at a position of 25,25 relative to the dropbox(dropboxOuter)

$(dragElement).animate({
            "left" : "25",  
            "top" : "25"
}, 1000 );

But this puts the element underneath the div ... any help

Upvotes: 0

Views: 56

Answers (1)

Marc Uberstein
Marc Uberstein

Reputation: 12541

There is a couple of bugs that I have fixed: http://jsfiddle.net/DTYEB/14/

  • Your first problem was that your target destination wasn't on the same level/layer.
  • You had double position (absolute & relative) on your container class
  • I have set your target dropbox to absolute (to avoid other elements that can change the top/left value)

Code i used to get relative drop:

$(dragElement).animate({
            left: $('#dropbox').position().left + 25,
            top: $('#dropbox').position().top + 25
        }, 1000);

Upvotes: 1

Related Questions