Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将一个图像拖放到另一个图像上HTML5_Html_Css - Fatal编程技术网

如何将一个图像拖放到另一个图像上HTML5

如何将一个图像拖放到另一个图像上HTML5,html,css,Html,Css,我需要能够使用HTML5将一个图像拖放到另一个图像上。有人能帮忙吗 我找到的都是关于如何将图像拖放到div,而不是其他图像的教程。 <!DOCTYPE HTML> <html> <head> <script> function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("T

我需要能够使用HTML5将一个图像拖放到另一个图像上。有人能帮忙吗

我找到的都是关于如何将图像拖放到
div
,而不是其他图像的教程。


    <!DOCTYPE HTML>
  <html>
  <head>
  <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>

 <div id="div1" ondrop="drop(event)"
  ondragover="allowDrop(event)"></div>

 <img id="drag1" src="img_logo.gif" draggable="true"
 ondragstart="drag(event)" width="336" height="69">

   </body>
   </html>
功能allowDrop(ev) { ev.preventDefault(); } 功能阻力(ev) { ev.dataTransfer.setData(“文本”,ev.target.id); } 功能下降(ev) { ev.preventDefault(); var data=ev.dataTransfer.getData(“文本”); ev.target.appendChild(document.getElementById(数据)); }
现在回答可能已经晚了,但这里有一个解决方案,以防有帮助,他给出了一个聪明的技巧,并链接了一个JSFIDLE:

欢迎使用堆栈溢出!请向我们展示您的代码和您的尝试。