JS實(shí)現(xiàn)超炫網(wǎng)頁(yè)煙花動(dòng)畫(huà)效果的方法
本文實(shí)例講述了JS實(shí)現(xiàn)超炫網(wǎng)頁(yè)煙花動(dòng)畫(huà)效果的方法。分享給大家供大家參考。具體分析如下:
非常炫的使用JS實(shí)現(xiàn)的一個(gè)網(wǎng)頁(yè)煙花燃放動(dòng)畫(huà)效果,能適應(yīng)JS做出這樣的動(dòng)畫(huà)來(lái)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>超炫網(wǎng)頁(yè)煙花效果</title>
</head>
<style type="text/css">
.fire{display:block; overflow:hidden; font-size:12px; position:absolute};
body{overflow:hidden; background:#000}
html{overflow:hidden; background:#000}
</style>
<body>
</body>
<script type="text/javascript">
var Fire = function(r, color) {
this.radius = r || 12;
this.color = color;
this.xpos = 0;
this.ypos = 0;
this.zpos = 0;
this.vx = 0;
this.vy = 0;
this.vz = 0;
this.mass = 1;
this.x =0;
this.y=0;
this.p = document.createElement("span");
this.p.className = "fire";
this.p.innerHTML = "*";
this.p.style.fontSize = this.radius + "px";
this.p.style.color = "#" + this.color;
}
Fire.prototype = {
append: function(parent) {
parent.appendChild(this.p);
},
setSize: function(scale) {
this.p.style.fontSize = this.radius * scale + "px";
},
setPosition:function(x, y) {
this.p.style.left = x + "px";
this.p.style.top = y + "px";
},
setVisible: function(b) {
this.p.style.display = b ? "block" : "none";
}
}
var fireworks = function() {
var fires = new Array();
var count = 150;
var fl = 250;
var vpx = 500;
var vpy = 300;
var gravity = .5;
var floor = 200;
var bounce = -.8;
var timer;
var wind = ((Math.floor(Math.random()*3) + 3)/10)*(Math.random()*2 - 1 > 0 ? 1 : -1)*.25;
var wpos = 0;
var wcount;
return {
init: function() {
wcount = 50 + Math.floor(Math.random() * 100);
for (var i=0; i<count; i++) {
var color = 0xFF0000;
color = (Math.random() * 0xFFFFFF).toString(16).toString().split(".")[0];
while(color.length < 6) {
color = "0" + color;
}
var fire = new Fire(12, color);
fires.push(fire);
fire.ypos = -100;
fire.vz = Math.random() * 6 - 3;
fire.vx = (Math.random()*2 - 1)*2 ;
fire.vy = Math.random()*-15 - 15;
fire.x = 500
fire.y = 600;
fire.append(document.body);
}
var that = this;
timer = setInterval(function() {
wpos++;
if (wpos >= wcount) {
wpos = 0;
wcount = 50 + Math.floor(Math.random() * 100);
wind = ((Math.floor(Math.random()*3) + 3)/10)*(Math.random()*2 - 1 > 0 ? 1 : -1)*.25;
}
for (var i=0;i<count; i++) {
that.move(fires[i]);
}
}, 30);
},
move: function(fire) {
fire.vy += gravity;
fire.x += fire.vx;
fire.y += fire.vy;
fire.vx += wind;
fire.setPosition(fire.x, fire.y);
if (fire.x < 0 || fire.x >1000 || fire.y < 0 || fire.y > 600) {
fire.vx = (Math.random()*2 - 1)*2;
fire.vy = Math.random()*-15 - 15;
fire.x = 500;
fire.y = 600;
fire.setPosition(fire.x, fire.y);
}
}
}
}
fireworks().init();
</script>
</html>
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
- JavaScript實(shí)現(xiàn)煙花綻放動(dòng)畫(huà)效果
- 原生JS實(shí)現(xiàn)煙花效果
- JS實(shí)現(xiàn)放煙花效果
- JS實(shí)現(xiàn)煙花爆炸效果
- JS實(shí)現(xiàn)網(wǎng)頁(yè)煙花動(dòng)畫(huà)效果
- javascript實(shí)現(xiàn)網(wǎng)頁(yè)背景煙花效果的方法
- JS基于面向?qū)ο髮?shí)現(xiàn)的放煙花效果
- 原生Js實(shí)現(xiàn)簡(jiǎn)易煙花爆炸效果的方法
- JS煙花背景效果實(shí)現(xiàn)方法
- js實(shí)現(xiàn)炫酷的煙花效果
相關(guān)文章
js實(shí)現(xiàn)倒計(jì)時(shí)時(shí)鐘的示例代碼
本篇文章主要是對(duì)js倒計(jì)時(shí)時(shí)鐘的示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12
淺析Javascript中bind()方法的使用與實(shí)現(xiàn)
下面小編就為大家?guī)?lái)一篇淺析Javascript中bind()方法的使用與實(shí)現(xiàn)。小編覺(jué)得挺2016-05-05
three.js實(shí)現(xiàn)炫酷的全景3D重力感應(yīng)
這篇文章主要為大家詳細(xì)介紹了three.js實(shí)現(xiàn)炫酷的全景3D重力感應(yīng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
JavaScript ECMA-262-3 深入解析(一):執(zhí)行上下文實(shí)例分析
這篇文章主要介紹了JavaScript ECMA-262-3 執(zhí)行上下文,結(jié)合實(shí)例形式詳細(xì)分析JavaScript ECMA執(zhí)行上下文相關(guān)概念、原理與操作注意事項(xiàng),需要的朋友可以參考下2020-04-04
JavaScript DSL 流暢接口(使用鏈?zhǔn)秸{(diào)用)實(shí)例
這篇文章主要介紹了JavaScript DSL 流暢接口(使用鏈?zhǔn)秸{(diào)用)實(shí)例,本文講解了DSL 流暢接口、DSL 表達(dá)式生成器等內(nèi)容,需要的朋友可以參考下2015-03-03
js與css實(shí)現(xiàn)彈出層覆蓋整個(gè)頁(yè)面的方法
這篇文章主要介紹了js與css實(shí)現(xiàn)彈出層覆蓋整個(gè)頁(yè)面的方法,分別以實(shí)例形式展示了彈出層覆蓋整個(gè)頁(yè)面的css樣式與js控制的實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12

