Friday, 23 August 2013

HTML 5 drag and drop to exact position

HTML 5 drag and drop to exact position

I want my element that I am dragging to drop into exactly the position it
was released. I'm not sure if I'm doing this right. So far I'm get the
drop coordinates in the drop event and then setting the top and left
properties. It works, sort of, except I have to offset the left and top
which makes me suspect there is something not right. Here is my function.
Can anyone point me in the right direction
var dropped = function (e) { cancel(e);
machine.parentNode.removeChild(machine);
e.target.appendChild(machine);
$(machine).css("top", (e.offsetY - 40) + 'px');
$(machine).css("left", (e.offsetX - 30) + 'px');
$("#text").html(e.offsetX + ' - ' + e.offsetY);
return false;
}

No comments:

Post a Comment