<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
<style>
body{
background-color: black;
position: relative;
overflow: hidden;
}
span{
font-size: 30px;
color: yellow;
position: absolute;
}
</style>
</head>
<body id="dv">
<input type="button" value="亮起来" id="btn"/>
<script src="common.js"></script>
<script>
my$("btn").onclick=function () {
setInterval(function () {
if(my$("dv").children.length<10){
for(var i=0;i<10;i++){
var obj=document.createElement("span");
my$("dv").appendChild(obj);
obj.innerText="★";
obj.setAttribute("id","index"+i);
}
}
var xArr=[],yArr=[];
for(var i=0;i<10;i++){
var x = parseInt(Math.random() * window.screen.height + 1);
var y = parseInt(Math.random() * window.screen.width + 1);
my$("index"+i).style.top=x+"px";
my$("index"+i).style.left=y+"px";
}
},100);
document.getElementById("dv").removeChild(my$("btn"));
};
</script>
</body>
</html>
效果图: