The specific code is as follows:
<!--The code is as follows. The bottom shows the 9 250*250 picture slices I used for testing--><!DOCTYPE html><html><head> <meta charset=utf-8> <title>drag Drag</title> <style> .box{ float: left; } img{ width: 150px; height:150px; } #puzzle{ font-size: 0; margin:80px auto; padding: 5px; width: 460px; } </style></head><body> <div id=puzzle> <div class=box><img <div class=box><img <div class =box><img <div class=box><img <div class=box><img <div class=box><img <div class=box><img <div class=box><img <div class=box><img </div> <script> var image = document.getElementsByTagName(img); var box = document.getElementsByClassName(box); image.draggable = true; var source = ; var nowImage; var nowImageBox ; var thenImage; for(let i=0;i<image.length;i++){ source = picture+i+.jpg; image[i].setAttribute(src,source); image[i].onmousedown = function(){ nowImage = this; nowImageBox = this.parentNode; } box[i].ondragover = function(event){ event.preventDefault( ); //Remove the default behavior of ondragover event, which cannot place data or elements to other elements by default} box[i].ondrop = function(event){ thenImage = box[i].childNodes[0]; box[i].appendChild(nowImage); nowImageBox.appendChild(thenImage); } } </script></body></html>Summarize
The above is the jigsaw puzzle implemented by the HTML5 drag and drop function introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for your support of the VeVb martial arts website!