- document.documentElement.clientWidth ==> 可见区域宽度
- document.documentElement.clientHeight ==> 可见区域高度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
body{background-color: black;}
span{width: 30px;
height: 30px;
background: url("pic1/star.png");
position:absolute;
background-size:100% 100%;
animation:move 1s alternate infinite ;
}
@keyframes move {
0%{
opacity:0;
}
100%{
opacity:1;
}
}
span:hover{transform: scale(2,2) rotate(180deg) !important;
transition:all 1s !important;;
}
</style>
</head>
<body>
<script>
window.onload = function () {
var screenW=document.documentElement.clientWidth;
var screenH=document.documentElement.clientHeight;
for(var i=0;i<300;i++){
var span=document.createElement("span")
document.body.appendChild(span);
var pointX=Math.random()*screenW;
var pointH=Math.random()*screenH;
span.style.left=pointX+"px";
span.style.top=pointH+"px";
var scale=Math.random()*2;
span.style.transform="scale('+scale+'','+scale+')";
var rate=Math.random()*1.6;
span.style.animationDelay=rate+"s";
}
}
</script>
</body>
</html>