JS框架_(JQuery.js)夜晚天空满天星星闪烁动画
百度云盘 传送门 密码:xftr
满天星星闪烁动画效果:

(可用星空动画来作为页面背景,白色文字改为文章或者其他的O(∩_∩)O)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery夜晚天空满天星星闪烁动画</title> <script src="js/jquery.min.js"></script> <style>
* {
box-sizing: border-box;
padding: 0;
margin: 0;
} body {
background: #22313f;
} #starsBox {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.75);
opacity: .5;
}
#starsBox span {
display: inline-block;
width: auto;
position: absolute;
border-radius: 100%;
transition: 100s linear;
} p {
position: fixed;
top: 50%;
left: 0;
right: 0;
text-align: center;
transform: translateY(-50%);
font-size: 40px;
font-weight: 900;
color: white;
text-shadow: 0 0 50px black;
text-transform: capitalize;
font-family: 'Roboto','Helvetica','Arial',sans-serif;
letter-spacing: 5px;
} p > span {
display: block;
font-size: 12px;
color: #bdc3c7;
margin-top: 30px;
font-weight: 100;
text-shadow: 0 0 50px black;
letter-spacing: 3px;
}
p > span > a {
font-weight: 700;
text-decoration: none;
color: #d64541;
padding-bottom: 2px;
border-bottom: 0px solid #d64541;
transition: 0.5s;
}
p > span > a:hover {
padding-bottom: 5px;
border-bottom: 2px solid #d64541;
}
</style>
</head>
<body> <div id="starsBox"></div> <p>Gary</p> <script type="text/javascript">
var cols = ['#f5d76e','#f7ca18','#f4d03f','#ececec','#ecf0f1','#a2ded0'];
var stars = 250; for (var i = 0; i <= stars; i++) { var size = Math.random()*3;
var color = cols[parseInt(Math.random()*4)]; $('#starsBox').prepend('<span style=" width: ' + size + 'px; height: ' + size + 'px; top: ' + Math.random()*100 + '%; left: ' + Math.random()*100 + '%; background: ' + color + '; box-shadow: 0 0 '+ Math.random()*10 +'px' + color + ';"></span>') ;
}; setTimeout(function(){
$('#starsBox span').each(function(){
$(this).css('top', Math.random()*100 + '%').css('left', Math.random()*100 + '%');
});
}, 1); setInterval(function(){
$('#starsBox span').each(function(){
$(this).css('top', Math.random()*100 + '%').css('left', Math.random()*100 + '%');
});
}, 100000);
</script> </body>
</html>
index.html
text-transform属性,可以轻易地实现英文字母大小写转换
capitalize; 单词首个字母大写
uppercase; 全部大写
lowercase; 全部小写
实现过程
Math.random()是令系统随机选取大于等于0.0且小于1.0的伪随机double值
<script type="text/javascript">
var cols = ['#f5d76e','#f7ca18','#f4d03f','#ececec','#ecf0f1','#a2ded0'];
var stars = 250; for (var i = 0; i <= stars; i++) { var size = Math.random()*3;
var color = cols[parseInt(Math.random()*4)]; $('#starsBox').prepend('<span style=" width: ' + size + 'px; height: ' + size + 'px; top: ' + Math.random()*100 + '%; left: ' + Math.random()*100 + '%; background: ' + color + '; box-shadow: 0 0 '+ Math.random()*10 +'px' + color + ';"></span>') ;
}; setTimeout(function(){
$('#starsBox span').each(function(){
$(this).css('top', Math.random()*100 + '%').css('left', Math.random()*100 + '%');
});
}, 1); setInterval(function(){
$('#starsBox span').each(function(){
$(this).css('top', Math.random()*100 + '%').css('left', Math.random()*100 + '%');
});
}, 100000);
</script>
关键代码
定义size为随机数,用于生成随机颜色和闪烁点随机距离
var size = Math.random()*3;
var color = cols[parseInt(Math.random()*4)];
设置星星闪烁、大小和颜色
$('#starsBox').prepend('<span style=" width: ' + size + 'px; height: ' + size + 'px; top: ' + Math.random()*100 + '%; left: ' + Math.random()*100 + '%; background: ' + color + '; box-shadow: 0 0 '+ Math.random()*10 +'px' + color + ';"></span>') ;
};
到达随机时间后星星闪烁和移动发生变化
setTimeout(function(){
$('#starsBox span').each(function(){
$(this).css('top', Math.random()*100 + '%').css('left', Math.random()*100 + '%');
});
}, 1);
设置每个星星之间的随机间隔
setInterval(function(){
$('#starsBox span').each(function(){
$(this).css('top', Math.random()*100 + '%').css('left', Math.random()*100 + '%');
});
}, 100000);
JS框架_(JQuery.js)夜晚天空满天星星闪烁动画的更多相关文章
- JS框架_(JQuery.js)绚丽的3D星空动画
百度云盘: 传送门 密码:8ft8 绚丽的3D星空动画效果(纯CSS) (3D星空动画可以用作网页背景,Gary为文本文字) <!doctype html> <html lang=& ...
- JS框架_(JQuery.js)圆形多选菜单选项
百度云盘 传送门 密码:zb1c 圆形多选菜单选项效果: <!DOCTYPE html> <html lang="en" > <head> &l ...
- JS框架_(JQuery.js)Tooltip弹出式按钮插件
百度云盘 传送门 密码:7eh5 弹出式按钮效果 <!DOCTYPE html> <html > <head> <meta charset="UTF ...
- JS框架_(JQuery.js)文章全屏动画切换
百度云盘 传送门 密码:anap 文章全屏动画切换效果 <!doctype html> <html lang="zh"> <head> < ...
- JS框架_(JQuery.js)动画效果鼠标跟随
百度云盘 传送门 密码 :4n9u 火狐浏览器上纯CSS_动画效果鼠标跟随效果: (作者:lily_lcj 传送门) <!DOCTYPE html PUBLIC "-//W3C//DT ...
- JS框架_(JQuery.js)点赞按钮动画
百度云盘 传送门 密码: 0ihy 点赞按钮动画效果: (点击一次随机生成一颗小爱心,作为点赞动画~) <!doctype html> <html lang="en&quo ...
- JS框架_(JQuery.js)图片相册掀开切换效果
百度云盘 传送门 密码:y0dk 图片掀开切换效果: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...
- JS框架_(JQuery.js)上传进度条
百度云盘 传送门 密码: 1pou 纯CSS上传进度条效果: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN ...
- JS框架_(JQuery.js)模拟刮奖
百度云盘:传送门 密码:6p5q 纯CSS模拟刮奖效果 <!DOCTYPE html> <html lang="en"> <head> < ...
随机推荐
- 检测Python程序本身是否已经在运行
为runner.py实现一个函数,检测是否有其他的runner.py进程在正在执行? 除主要用到os模块,还用到了第三方模块psutil
- nginx配置:静态访问txt文件
有一个A网站,访问的话会重定向跳转到B网站上,在A网站的nginx配置文件中配置的有如下: location / { rewrite ^/(.*) http://B/$1 redirect; } 现在 ...
- js里生成guid
function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | , ...
- mysql的索引为什么要使用B+树而不是其他树?
总结 1.InnoDB存储引擎的最小存储单元是页,页可以用于存放数据也可以用于存放键值+指针,在B+树中叶子节点存放数据,非叶子节点存放键值+指针. 2.索引组织表通过非叶子节点的二分查找法以及指针确 ...
- [转载]static in Java
来源:https://www.cnblogs.com/chenssy/p/3386721.html 一. static代表着什么 在Java中并不存在全局变量的概念,但是我们可以通过static来实现 ...
- js中new到底做了什么?如何重写new?
new 构造函数()执行顺序1.在堆中开辟对象内存空间, 记为obj2.在obj 中添加__proto__属性并指向 构造函数.prototype3.将构造函数中的this 指向obj4.执行构造函数 ...
- Django框架——进阶之AJAX
<script>$("#b1").on("click", function () { // 点击 id是b1的按钮要做的事儿 var i1 = $( ...
- TVM:一个端到端的用于开发深度学习负载以适应多种硬件平台的IR栈
TVM:一个端到端的用于开发深度学习负载以适应多种硬件平台的IR栈 本文对TVM的论文进行了翻译整理 深度学习如今无处不在且必不可少.这次创新部分得益于可扩展的深度学习系统,比如 TensorFlo ...
- javascript中的数据渲染与提取
table数据 <div id="tableDiv" style="overflow-x: scroll"> <table class=&qu ...
- Linux下svn服务器的安装与配置-备份-恢复-计划任务
简介:SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subvers ...