js實(shí)現(xiàn)星星海特效的示例
首先需要獲取屏幕大?。?/p>
var screenWidth = document.documentElement.clientWidth; var screenHeight = document.documentElement.clientHeight;
接著可以定義動(dòng)畫(huà)(星星透明度):
@keyframes flash {
0%{opacity: 0}
25%{opacity: 0.25}
50%{opacity: 0.5}
75%{opacity: 0.75}
100%{opacity: 1}
}
全部代碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 70px;
height: 80px;
background: url("./images/star.jpg") no-repeat;
animation: flash 1s;
}
body{
background-color: black
}
@keyframes flash {
0%{opacity: 0}
25%{opacity: 0.25}
50%{opacity: 0.5}
75%{opacity: 0.75}
100%{opacity: 1}
}
</style>
</head>
<body>
<script>
var screenWidth = document.documentElement.clientWidth;
var screenHeight = document.documentElement.clientHeight;
// 生產(chǎn)50個(gè)星星
for (let i = 0; i <50 ; i++) {
var box=document.createElement('div');
document.body.appendChild(box);
x=Math.random()*screenWidth;
y=Math.random()*screenHeight;
box.style.position='relative';
box.style.left=x+'px';
box.style.right=y+'px';
}
boxList=document.getElementsByTagName("div");
for (let i = 0; i < boxList.length; i++) {
boxList[i].onmouseover=function () {
this.style.transform='scale(1.5,1.5)';
};
boxList[i].onmouseout=function () {
this.style.transform='scale(1,1)';
};
}
</script>
</body>
</html>
效果如下:

以上就是js實(shí)現(xiàn)星星海特效的示例的詳細(xì)內(nèi)容,更多關(guān)于js 星星海特效的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- JS 中使用Promise 實(shí)現(xiàn)紅綠燈實(shí)例代碼(demo)
- js實(shí)現(xiàn)點(diǎn)擊煙花特效
- js實(shí)現(xiàn)3D粒子酷炫動(dòng)態(tài)旋轉(zhuǎn)特效
- js+css3實(shí)現(xiàn)簡(jiǎn)單時(shí)鐘特效
- JS實(shí)現(xiàn)頁(yè)面鼠標(biāo)點(diǎn)擊出現(xiàn)圖片特效
- js實(shí)現(xiàn)無(wú)縫輪播圖特效
- JS實(shí)現(xiàn)網(wǎng)頁(yè)時(shí)鐘特效
- js實(shí)現(xiàn)煙花特效
- 利用js實(shí)現(xiàn)簡(jiǎn)易紅綠燈
相關(guān)文章
JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格的方法詳解
這篇文章主要為大家介紹了JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-01-01
代碼短小的js div層拖動(dòng)實(shí)現(xiàn)代碼[兼容IE與Firefox]
代碼短小的js div層拖動(dòng)實(shí)現(xiàn)代碼[兼容IE與Firefox],需要的朋友可以參考下.2010-05-05
微信小程序動(dòng)態(tài)生成二維碼的實(shí)現(xiàn)代碼
這篇文章主要介紹了微信小程序動(dòng)態(tài)生成二維碼的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-07-07
深入淺析JavaScript中的in關(guān)鍵字和for-in循環(huán)
這篇文章主要介紹了JavaScript中的in關(guān)鍵字和for-in循環(huán),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
fetch 如何實(shí)現(xiàn)請(qǐng)求數(shù)據(jù)
這篇文章主要介紹了fetch 如何實(shí)現(xiàn)請(qǐng)求數(shù)據(jù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12
JavaScript數(shù)學(xué)對(duì)象Math操作數(shù)字的方法
這篇文章主要為大家介紹了JavaScript數(shù)學(xué)對(duì)象Math操作數(shù)字的方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05

