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> < ...
随机推荐
- celery异步发送邮件
利用Django框架发送邮件的详细过程,在前两天的博客中有所记录,但是单纯的那样发邮件是有非常大的问题的,这就需要celery异步发送来解决 首先我们来看一下邮件发送的过程: Django网站先发送到 ...
- Smarty内置函数之config_load
config_load的作用是: 用于从配置文件中加载变量,属性file引入配置文件名,另外若配置文件包含多个部分,可以使用属性section指定从那部分取得变量(若不指定,将会引入失败). 实例: ...
- Python 入门 之 print带颜色输出
Python 入门 之 print带颜色输出 1.print带颜色输出书写格式: 开头部分: \033[显示方式; 前景色 ; 背景色 m 结尾部分: \033[0m 详解: 开头部分的三个参数: 显 ...
- Springboot实现上传文件接口,使用python的requests进行组装报文上传文件的方法
记录瞬间 近段时间使用Springboot实现了文件的上传服务,但是在使用python的requests进行post上传时,总是报错. 比如: 1.Current request is not a m ...
- Erasing Substrings CodeForces - 938F (字符串dp)
大意: 给定字符串$s$, 长度为$n$, 取$k=\lfloor log2(n)\rfloor$, 第$i$次操作删除一个长度为$2^{i-1}$的子串, 求一种方案使得, $k$次操作后$s$的字 ...
- java中内部类
package com.xt.instanceoftest; import com.xt.instanceoftest.Body.Heart; public class StaticInnerClas ...
- Delphi 数组与记录类型
- SecureCRT 连接 Centos7.0 (NAT模式),且能连接公网。
1.打开物理主机运行-输入cmd,输入ipconfig,获取物理主机ip地址. ip:192.168.11.138 2.点击网络适配器,选择NAT模式. 3.点击Centos界面左上角-编辑-虚拟网络 ...
- MSSQL数据库备份还原常用SQL语句及注意
.备份数据库 backup database db_name to disk='d:\db_name.bak' with format --通过使用with format可以做到覆盖任何现有的备份和创 ...
- zabbix 添加 host item
Zabbix常用术语 host(主机):监控的网络设备,可由IP或DNS名称指定. host Group(主机组):Host的逻辑容器,可以包含主机和模板. Item(监控项):一个特定监控指标的相关 ...