- document.documentElement.clientWidth ==> 可見區(qū)域?qū)挾?/li>
- document.documentElement.clientHeight ==> 可見區(qū)域高度
<!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>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。