漂亮的JavaScript烟花特效代码 - www.webdm.cn

html,body{background:#000; height:100%; margin:0px; padding:0px;color:#FFF;}

.ball{color:#FF0000; position:absolute; font-size:16px;}

.star{color:#FF0000; position:absolute; font-size:4px;}

function Fireworks(sky, loop){

this.sky = sky;

this.skyWidth = document.body.clientWidth || document.documentElement.clientWidth;

this.skyHeight= document.body.clientHeight || document.documentElement.clientHeight;

this.x = this.y = 0;

this.step = 20;

this.delay = 30;

this.stars = [];

this.r = 10;

this.step2 = 7;

this.radius = 90;

this.angle = 45;

this.num = 16;

this.loop = loop;

this.degree = 2;

this.t = 0;

this.delt = 0;

this.max = 30;

this.cur = 1;

this.points = null;

}

Fireworks.prototype = {

init : function(){

this.x = parseInt(this.skyWidth/1.3 * Math.random()) + this.skyWidth / 8;

this.y = this.skyHeight;

this._y = parseInt((this.skyHeight / 4) * Math.random()) + this.skyHeight / 5;

},

setOpacity : function(obj, p){

if(p > 85){

var opacity = 100 - (p - 85) * 4;

if(document.all){

obj.style.filter = "alpha(opacity=" + opacity + ")";

}else{

obj.style.MozOpacity = opacity / 100;

}

}

},

getNextPoint : function(degree, coeff, t){

var tt = 1.0 - t;

for(var rr = 1; rr <= degree; rr++){

for(var i=0; i <= degree-rr; i++){

coeff[i] = tt * coeff[i] + t * coeff[i+1];

}

}

return coeff[0];

},

showBall : function(){

this.ball = document.createElement("div");

this.ball.innerHTML = "●";

this.ball.className = "ball";

this.ball.style.left = this.x + "px";

this.ball.style.top = this.y + "px";

this.sky.appendChild(this.ball);

},

moveBall : function(){

var self = this;

if(this.y > this._y){

var p = parseInt((this.skyHeight - this.y) / (this.skyHeight - this._y)*10);

this.y -= (this.step - p * 1.6);

this.ball.style.fontSize = 16 - p + "px";

this.ball.style.top = this.y + "px";

setTimeout(function(){self.moveBall();}, this.delay);

}else{

this.fire();

}

},

hideBall : function(){

this.sky.removeChild(this.ball);

this.ball = null;

},

showStars : function(){

var colors = ['#FF0000','#FF00FF','#00FF00','#00FFFF','#FFFF00','#FF0000','#FF00FF','#00FF00','#00FFFF','#FFFF00'];

var n = cs = parseInt(Math.random() * colors.length / 2);

var cc = parseInt(Math.random() * colors.length / 2);

var colorMode = parseInt(Math.random() * 2);

var star = Math.round(Math.random()) == 1 ? "★" : "☆";

this.r = 10;

this.radius = Math.round(Math.random() * 30) + 60;

this.num = Math.round(Math.random() * 5 + 5) * 2;

this.angle = 180 / this.num * 2;

for(var i=1; i<=this.num; i++){

this.stars[i] = document.createElement("div");

this.stars[i].innerHTML = star;

this.stars[i].className = "star";

if(colorMode == 1){

this.stars[i].style.color = colors[n];

if(++n > cs + cc)

n = cs;

}else{

this.stars[i].style.color = colors[parseInt(Math.random() * colors.length)];

}

this.sky.appendChild(this.stars[i]);

}

},

moveStars : function(){

var self = this;

if(this.r < this.radius){

var p = this.step2 - parseInt(this.r / this.radius * 5);

p = p < 1 ? 1 : p;

this.r += p;

p = parseInt(this.r / this.radius * 100);

for(var i=1; i<=this.num; i++){

this.stars[i].style.left = this.x - Math.round(this.r * Math.sin(Math.PI - (Math.PI / 180 * this.angle * i))) + "px";

this.stars[i].style.top = this.y - Math.round(this.r * Math.cos(Math.PI - (Math.PI / 180 * this.angle * i))) + "px";

this.stars[i].style.fontSize = 4 + p/10 + "px";

this.setOpacity(this.stars[i], p);

}

setTimeout(function(){self.moveStars();}, this.delay);

}else{

setTimeout(function(){self.hideStars();}, 200 * Math.random());

}

},

initBezier : function(){

var coeff_x = [];

var coeff_y = [];

this.points = [];

this.t = 0;

this.delt = 1.0 / this.max;

this.cur = 1;

var a = parseInt(Math.random() * 5) * 90;

coeff_x[0] = this.x;

coeff_y[0] = this.y;

for(var i=1; i<=this.num; i++){

coeff_x[1] = this.x + Math.sin(Math.PI - (Math.PI / 180 * this.angle * i)) * this.radius/2;

coeff_y[1] = this.y + Math.cos(Math.PI - (Math.PI / 180 * this.angle * i)) * this.radius/2;

coeff_x[2] = this.x + Math.sin(Math.PI - (Math.PI / 180 * (a-this.angle * i))) * this.radius;

coeff_y[2] = this.y + Math.cos(Math.PI - (Math.PI / 180 * (a-this.angle * i))) * this.radius;

this.points[(i-1)*2] = coeff_x.slice(0);

this.points[(i-1)*2+1] = coeff_y.slice(0);

}

},

moveStars2 : function(){

var self = this;

if(this.cur < this.max){

this.t += this.delt;

this.cur++;

p = parseInt(this.cur / this.max * 100);

for(var i=1; i<=this.num; i++){

this.stars[i].style.left = this.getNextPoint(this.degree, this.points[(i-1)*2], this.t) + "px";

this.stars[i].style.top = this.getNextPoint(this.degree, this.points[(i-1)*2+1], this.t) + "px";

this.stars[i].style.fontSize = 4 + p/10 + "px";

this.setOpacity(this.stars[i], p);

}

setTimeout(function(){self.moveStars2();}, this.delay);

}else{

setTimeout(function(){self.hideStars();}, 200 * Math.random());

}

},

hideStars : function(){

for(var i=1; i<=this.num; i++){

this.sky.removeChild(this.stars[i]);

this.stars[i] = null;

if(this.points != null){

delete this.points[(i-1)*2];

delete this.points[(i-1)*2+1];

}

}

if(this.points){

delete this.points;

}

this.points = null;

if(this.loop){

this.play();

}

},

fire : function(){

this.hideBall();

this.showStars();

var effect = parseInt(Math.random() * 2) + 1;

switch(effect){

case 1:

this.moveStars();

break;

case 2:

this.initBezier();

this.moveStars2();

break;

}

},

play : function(){

this.init();

this.showBall();

this.moveBall();

}

};

window.onload = function(){

for(var i=0; i<5; i++)

new Fireworks(document.body, true).play();

};

网页代码站 - 最专业的代码下载网站 - 致力为中国站长提供有质量的代码!

html5烟花特效代码,漂亮的JavaScript烟花特效代码相关推荐

  1. HTML5七夕情人节表白网页制作【css3爱心表白背景特效】HTML+CSS+JavaScript 520情人节代码制作

    这是程序员表白系列中的100款网站表白之一,旨在让任何人都能使用并创建自己的表白网站给心爱的人看. 此波共有100个表白网站,可以任意修改和使用,很多人会希望向心爱的男孩女孩告白,生性腼腆的人即使那个 ...

  2. 各种页面刷新代码大全,asp/javascript刷新页面代码

    页面自动刷新代码大全,基本上所有要求自动刷新页面的代码都有,大家可以自由发挥做出完美的页面. 1) 10表示间隔10秒刷新一次 2) <script> window.location.re ...

  3. HTML粒子碰撞烟花,html5 canvas漂亮的粒子烟花背景动画特效

    特效描述:html5 canvas 漂亮的粒子烟花 背景动画特效.html5 canvas漂亮的粒子烟花背景动画特效 代码结构 1. HTML代码 class Vector2 { constructo ...

  4. HTML5七夕情人节表白网页(庆祝生日蛋糕烟花特效) HTML+CSS+JavaScript

    HTML5七夕情人节表白网页❤庆祝生日蛋糕烟花特效❤ HTML+CSS+JavaScript 这是程序员表白系列中的100款网站表白之一,旨在让任何人都能使用并创建自己的表白网站给心爱的人看. 此波共 ...

  5. HTML5+Canvas漂亮的3D烟花动画生日特效,节日特效,烟花

    fireworks HTML5+Canvas漂亮的3D烟花动画生日特效,节日特效,烟花 https://github.com/louislivi/fireworks

  6. html烟花特效案例,HTML5前端特效库 css3 按钮粒子烟花特效源码

    HTML5前端特效库 css3 按钮粒子烟花特效源码 效果图 各位长友大家上午好! 今天给大家带来的是 css3 按钮粒子烟花特效源码! 大家可以按照自己的意愿进行修改! 有想要文件版源码的可以 在我 ...

  7. JavaScript烟花设计

    JavaScript烟花设计 今天给大家分享一篇自己用JavaScript实现烟花设计,主要运用了js+html语言,实现动态效果,展现出月明星稀下城市一片宁静的情景,令人心旷神怡. 文章目录 系列文 ...

  8. Python表白代码:“ 星光月夜烟花 皆归你,我也归你”

    导语 "慢品人间烟火色 闲观人间岁月长" ---致自己 遇见我以后,我们的故事就开始了,愿你历经山河,仍觉得人间值得. ​ **星光月夜烟花皆归你,我也归你.**关于烟花大家都​知 ...

  9. HTML5期末大作业:重庆火锅网站设计——代码质量好-重庆火锅(5页) HTML+CSS+JavaScript 大学生网页制作期末作业

    HTML5期末大作业:重庆火锅网站设计--代码质量好-重庆火锅(5页) HTML+CSS+JavaScript 大学生网页制作期末作业 常见网页设计作业题材有 个人. 美食. 公司. 学校. 旅游. ...

  10. 100行JS代码实现❤坦克大战js小游戏源码 HTML5坦克大战游戏代码(HTML+CSS+JavaScript )

    坦克大战js小游戏源码 HTML5坦克大战游戏代码(HTML+CSS+JavaScript ) HTML5坦克大战网页小游戏,完美还原小霸王学习机效果,以坦克战斗及保卫基地为主题,属于策略型类游戏. ...

最新文章

  1. GDAL库简介以及在Windows下编译过程
  2. 基于keepalived搭建MySQL高可用集群
  3. 【bzoj3575】 Hnoi2014—道路堵塞
  4. Android Studio运行报错Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled
  5. 汉诺塔V - ACM解决方法
  6. hibernateTemplate 的find 查找方法
  7. X大佬:建议被降级降薪员工主动辞职,网友炸了
  8. android settheme不起作用,android-主题,样式和别名嵌套不起作用
  9. HDU 3197 Game(树删边)
  10. 学习vim: vim cheat sheet
  11. 为PyCharm添加不同解释器
  12. Python开发环境搭建方法简述
  13. k8s-有状态应用编排
  14. 分享餐饮管理组织结构流程图模板
  15. 2022年油猴(tampermonkey)超简单安装
  16. python入门的小问题:计算复利函数
  17. 【Spring Cloud Alibaba 实战 | 总结篇】Spring Cloud Gateway + Spring Security OAuth2 + JWT 实现微服务统一认证授权和鉴权
  18. 天津大学异地新校区,首次曝光设计效果图!
  19. Logstash filter grok正则的使用及介绍
  20. Sentinel的学习

热门文章

  1. 机器学习的十大经典算法,面试必问
  2. Monkey命令参数详解
  3. garmone build on sb2
  4. 色差大调色难?实操讲解如何去除谷歌影像色差
  5. oracle 取时间的日期函数,Oracle日期函数简介
  6. 防止百度网盘和谐/暗中观察我的资源
  7. SpringBoot修改内置tomcat版本
  8. Java 复制文件并改名
  9. 算法设计与分析课后习题答案
  10. 最新信恒第四方支付系统源码+服务器直接打包