<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div { width: 400px; height: 400px; background-color: cadetblue; } span { font-size: 30px; color: yellow; position: absolute; } </style> </head> <body> <input type="button" value="亮起来" id="btn"> <div id="dv"> </div> <script> function my$(id) { return document.getElementById(id); }; my$("btn").onclick=function () { setInterval(function () { my$("dv").innerHTML="<span>☆</span>"; var x = parseInt(Math.random()*400 +1); var y = parseInt(Math.random()*400 +1); my$("dv").firstElementChild.style.left=x +"px"; my$("dv").firstElementChild.style.top=y +"px"; },10); }; </script> </body> </html>
生成随机数让星星动起来
最新推荐文章于 2023-11-16 17:32:38 发布