4

Here, is my fiddle for jquery drag, drop and clone feature.

Problem:

My problem is: when ever I drop element, it is showing:

position: {top: 0, left: 0}

only for draggable, clone and droppable element.

I have also written code for finding position using only draggable function and that is working fine. I want this behavior in draggable, droppable with clone feature

Please visit JSFiddle

fiddle

full-screen output

przbadu
  • 5,769
  • 5
  • 42
  • 67

1 Answers1

6

Finally, resolved the problem. The problem was, I was using ui.draggable.position(); for storing dropped position to database, which was wrong.

The actual position we need to store is:

// position of the draggable minus position of the droppable
// relative to the document
leftPosition  = ui.offset.left - $(this).offset().left;
topPosition   = ui.offset.top - $(this).offset().top;

Reference: How do I get the coordinate position after using jQuery drag and drop?

Updated Jsfiddle with working example

http://jsfiddle.net/przbadu/rkvdffe3/18/

http://jsfiddle.net/przbadu/rkvdffe3/18/embedded/result/

Community
  • 1
  • 1
przbadu
  • 5,769
  • 5
  • 42
  • 67
  • Old post here, but thought I would ask anyways. I noticed that when you drop an element onto the page it loads 2 coordinates. So after you move it again, it loads a more accurate coordinates. Do you have any more updated code on this? This is very similar to what I'm looking to accomplish, but not with signatures. Thanks! – Justin Dec 13 '17 at 06:02
  • @Justin Yes, it's too old post. Unfortunately I don't have updated code. – przbadu Dec 13 '17 at 07:03
  • Are you using it anywhere? or know of another solution similar to this? – Justin Dec 13 '17 at 07:18
  • I was using this for my old project but i don't have access to that private repository now :) – przbadu Dec 13 '17 at 07:19
  • No problem, just thought id ask. This might have gotten me to the next step anyways. Thanks! – Justin Dec 13 '17 at 07:20