All,
I'm trying to use HTML5 drag and drop and with javascript. However, I can't get the ability to drop an item into the same location of where the mouse gets released. Anytime I drop an item into the destinationContainer the X and Y coordinates don't work for top and left styles respectively.
I have included a jsfiddle for reference. In addition, I have included the snippet code that represents my drop event.
Thanks for any help!
https://jsfiddle.net/mdevera/94vzuo89/2/
function drop(event) {
console.log("drop");
event.preventDefault();
var id = event.dataTransfer.getData("text/plain");
if ((id === "item1" || id === "item2") && event.target.className === "destinationContainer" ) {
var clone = document.getElementById(id).cloneNode(true);
clone.id = Math.floor((Math.random() * 100) + 1);
/// Style for making item drop in the same mouse location of drop. Does not work.
//clone.style.top = event.clientY + "px";
//clone.style.left = event.clientX + "px";
clone.style.position = "relative";
event.target.appendChild(clone);
}
}