js实现星星海特效的示例
编程学习 2021-07-04 14:06www.dzhlxh.cn编程入门
这篇文章主要介绍了js实现星星海特效的示例,帮助大家制作网页特效,感兴趣的朋友可以了解下
首先需要获取屏幕大小:
var screenWidth = document.documentElement.clientWidth; var screenHeight = document.documentElement.clientHeight;
接着可以定义动画(星星透明度):
@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; // 生产50个星星 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实现星星海特效的示例的详细内容,更多关于js 星星海特效的资料请关注狼蚁SEO其它相关文章!
编程语言
- ThinkPad 笔记本如何调节LCD屏幕亮度
- Dreamweaver制作网页打开特效教程
- Win10 Mobile 10586升级后无限重启怎么办 硬重启帮您
- Win8系统提示音频设备有问题有一个或多个音频服
- Xbox One版Win10首个预览版9月份发布
- 如何在textarea文本输入区内实现换行
- Win10 Build 9901系统更新 预览版新版本下载
- McAfee Framework存在远程格式串处理漏洞
- Win10家庭版今日(7月30)正式在中国官方商城开卖
- Win10 Mobile预览版更新完10536.1000后才收到10536.100
- Win10 RS2更新了什么-Win10 RS2最终版本号1704首曝
- Windows7如何查看回收站对应的文件夹有哪些方法
- Win10让Charms栏回归桌面的方法教程
- 取消Windows XP系统开机启动画面的小技巧
- win8系统怎么下载安装USB百兆网卡?
- XP系统下磁盘空间变少了怎么办?XP系统磁盘空间