Hi there,
I want to use drag&drop in HTML UI made with PlayCanvas. I find an example of what i want in my UI there : https://www.w3schools.com/html/html5_draganddrop.asp
The problem is I don’t know why I can’t use ondragstart event added by the script.
There is my script to create my drag element :
PageContructor.prototype.setupDraggableObject = function(name, id){
var tempDiv = document.createElement('div');
tempDiv.classList.add('placement');
tempDiv.classList.add('box-solid');
tempDiv.setAttribute('id', 'button' + id);
tempDiv.setAttribute('draggable', true);
tempDiv.innerHTML = "<p class=\"text-in\">" + name + "</p>";
if (tempDiv) {
console.log("Event added");
tempDiv.addEventListener('ondragstart', function() {
console.log('dragging');
}.bind(this), false);
}
document.getElementById('products').appendChild(tempDiv);
};
Actually, in the console, I got the “Event added” but not the “dragging” when I try to drag elements.
Did something is wrong with my code ?
Thanks for your answers.