js實(shí)現(xiàn)星星海特效的示例
首先需要獲取屏幕大小:
var screenWidth = document.documentElement.clientWidth; var screenHeight = document.documentElement.clientHeight;
接著可以定義動(dòng)畫(星星透明度):
@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)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. python公司內(nèi)項(xiàng)目對(duì)接釘釘審批流程的實(shí)現(xiàn)2. Python 簡(jiǎn)介3. Python本地及虛擬解釋器配置過(guò)程解析4. Notepad++如何配置python?配置python操作流程詳解5. Python 利用flask搭建一個(gè)共享服務(wù)器的步驟6. Python自動(dòng)化之定位方法大殺器xpath7. python用zip壓縮與解壓縮8. Python操作Excel工作簿的示例代碼(*.xlsx)9. Python importlib模塊重載使用方法詳解10. Python中Anaconda3 安裝gdal庫(kù)的方法
