<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
div{
width: 500px;
height: 500px;
border: 1px solid yellow;
background-color: black;
position: relative;
}
span{
position: absolute;
color: yellow;
}
</style>
<body>
</body>
<input type="button" value="动起来" id="box" />
<div id="dv"></div>
<script>
function my(id) {
return document.getElementById(id);
}
my("box").onclick = function() {
setInterval(function() {
my("dv").innerHTML="<span>五角星</span>";
var x = parseInt(Math.random() * 500 + 1);
var y = parseInt(Math.random() * 500 + 1);
my("dv").firstElementChild.style.left = x + "px";
my("dv").firstElementChild.style.top = y + "px";
}, 100)
}
</script>
</html>
js漫天小星星
最新推荐文章于 2019-10-31 17:15:56 发布