Według the documentation na przeciągnij HTML5 i upuść API, dwa zdarzenia są opalane gdy element zostanie upuszczony:Czy istnieje zdefiniowana kolejność między zdarzeniami przeciągania i upuszczania?
drop
zdarzenie jest zwolniony z cel upuszczeniadragend
zdarzenie jest opalane od źródła drag
w ten prosty test (patrz fragment), zdarzenie drop
zawsze wyzwalana tuż przed zdarzeniem dragend
(przynajmniej w Chrome), ale nie mogę znaleźć nic na temat zamawiania tych wydarzeń w sp ec.
Czy zdefiniowano kolejność tych zdarzeń, czy można je uruchomić w dowolnej kolejności?
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
console.log("drop at " + Date.now());
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
function dragend(ev) {
console.log("dragend at " + Date.now());
}
#div1 {
background-color: red;
height: 100px;
width: 100px;
}
#drag1 {
background-color: green;
height: 50px;
width: 50px;
}
<div>Drag the green square in to the red one</div>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)" width="100px" height="100px"></div>
<div id="drag1" draggable="true" ondragstart="drag(event)" ondragend="dragend(event)" width="50px" height="50px">
To samo zamówienie dla Firefoksa – gal007