百度云盘  传送门  密码: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);

转载于:https://www.cnblogs.com/1138720556Gary/p/9374845.html

JS框架_(JQuery.js)夜晚天空满天星星闪烁动画相关推荐

  1. JS框架_(JQuery.js)纯css3进度条动画

    百度云盘 传送门 密码:wirc 进度条动画效果: <!DOCTYPE html> <htmllang="zh"> <head><meta ...

  2. JS框架_(JQuery.js)带阴影贴纸标签按钮

    百度云盘 传送门 密码:azo6 纯CSS带阴影贴纸标签按钮效果: <!doctype html> <html> <head> <meta charset=& ...

  3. JS框架_(Typed.js)彩色霓虹灯发光文字动画

    百度云盘 传送门 密码:8oei 发光文字动画效果: <!doctype html> <html> <head> <meta charset="ut ...

  4. JS框架_(Progress.js)圆形动画进度条

    百度云盘 传送门 密码: 6mcf 圆形动画进度条效果: <!DOCTYPE html> <html lang="en"> <head>< ...

  5. DHTMLX JS框架,日程JS框架 功能强大 收藏!

    DHTMLX JS框架,日程JS框架  功能强大 收藏! http://dhtmlx.com DHTMLX Touch 它是针对移动和触摸设备的JavaScript 框架.DHTMLX Touch基于 ...

  6. Js框架的JQuery基本用法

    1.jQuery基本用法 常用的js框架 1.dojo面向对象的js框架 2.extjs学习成本比较高,它提供大量的丰富组件,它效果展示非常好 3.prototype早期比较流行的js框架 4.ang ...

  7. css框架和js框架_优雅设计的顶级CSS框架

    css框架和js框架 Brief discussion: 简要讨论: Well, who doesn't want their website or web page to look attracti ...

  8. css框架和js框架_如何选择正确CSS工具包和框架

    css框架和js框架 A Q&A about Susy and other toolkits, with Miriam Suzanne. 与Miriam Suzanne一起有关Susy和其他工 ...

  9. 基于 Egg.js 框架的 Node.js 服务构建之用户管理设计

    转载需经本人同意且标注本文原始地址:https://zhaomenghuan.github.io/blog/nodejs-eggjs-usersytem.html 前言 近来公司需要构建一套 EMM( ...

  10. 基于 Egg.js 框架的 Node.js 服务构建之用户管理设计 1

    前言 近来公司需要构建一套 EMM(Enterprise Mobility Management)的管理平台,就这种面向企业的应用管理本身需要考虑的需求是十分复杂的,技术层面管理端和服务端构建是架构核 ...

最新文章

  1. 爱,催人泪下......
  2. 谷歌魔改Transformer登NeurIPS 2021!一层8个token更好用
  3. 花最少的钱,训超6的机器人:谷歌大脑推出机器人强化学习平台,硬件代码全开源...
  4. Go的GAPATH详解
  5. iframe 按比例缩放_不按常理出牌!5个Excel灵异事件,能让你崩溃
  6. BPMS表单版本控制设计
  7. for in for of区别_(for…in) VS (for…of)
  8. ubuntu安装环境软件全文档
  9. angular设置referer_Angular-cli 构建应用的一些配置
  10. delphi 异步 调用 带参数_如何在 Spring 异步调用中传递上下文
  11. 微服务架构下的熔断框架:hystrix-go
  12. php中文字怎么上下居中,CSS怎么设置垂直居中?
  13. matlab求解含两个累加公式的方程,使用fsolve 函数求解含两个参数的多个方程问题,希望有会的人帮...
  14. Atitit 各种设计图纸分类 目录 1. Atitit 常见软件设计图纸总结 2 1.1. Uml系列图纸 2 1.2. Er图 req需求图 2 1.3. Parametric diagr
  15. VS技巧 使用Visual Studio Icon Patcher将2010的图片注入到2012中
  16. matlab封闭曲线拟合 (针对一些列离散点)
  17. jxd android 4.1刷机包,金星JXD V3固件
  18. 给redis设置密码
  19. RoundedCorners
  20. jsp返回上一个页面并刷新

热门文章

  1. U盘PE系统的制作和安装(win7、win10)
  2. Linux的进程管理之进程与线程—2
  3. 微信小程序自定义生成动态分享内容
  4. W: Possible missing firmware /lib/firmware/i915/skl_guc_49.0.1.bin for module i915
  5. php大道至简之框架
  6. ccf试题1:分蛋糕
  7. 可以嵌入ppt的课堂点名器_异地授课+大屏直播,打造沉浸式线下多地互动智慧课堂...
  8. A - Round decimals
  9. 系统临时文件的写和读:createTempFile和tempFileContent
  10. CityEngine + Python自动化建模原理【系列文章之三】