javascript - HTML5 Determine drop drop object -
in w3school example can lots of data event , target object how determine object dropped on target?
<!doctype html> <html> <head> <style> #div1 {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;} </style> <script> function allowdrop(ev) { ev.preventdefault(); } function drag(ev) { ev.datatransfer.setdata("text", ev.target.id); } function drop(ev) { ev.preventdefault(); var data = ev.datatransfer.getdata("text"); ev.target.appendchild(document.getelementbyid(data)); } </script> </head> <body> <p>drag w3schools image rectangle:</p> <div id="div1" ondrop="drop(event)" ondragover="allowdrop(event)"></div> <br> <img id="drag1" src="img_logo.gif" draggable="true" ondragstart="drag(event)" width="336" height="69"> </body> </html>
in drop function, id of element dropping in defined 'data'. can therefore write var element = document.getelementbyid(data)
now, element variable object , can information wan't it, pass function etc.
Comments
Post a Comment