模拟贪吃蛇
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> window.onload = function () { var aDiv = document.getElementsByTagName("div"); document.onmousemove = function (ev) { var oEvent = ev || event; for (var i = aDiv.length - 1; i > 0; i--) { aDiv[i].style.left = aDiv[i - 1].offsetLeft + 'px'; aDiv[i].style.top = aDiv[i - 1].offsetTop + 'px'; } aDiv[0].style.left = oEvent.clientX + "px"; aDiv[0].style.top = oEvent.clientY + "px"; } } </script> <style> div { width: 20px; height: 20px; background: red; position: absolute; } </style> </head> <body> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </body> </html>
用我拥有,换你没有,竭尽所有