来源:蜘蛛抓取(WebSpider)
时间:2016-05-14 10:30
标签:
javascript math.ceil
网页设计教程与开发
提供各种常见网页效果
提供各种各样的设计教程
装扮QQ,让QQ变得更酷
设计参考,提高自升水平
学习服务器和操作系统
提供各种素材和工具
收藏学习资料
您现在的位置:&&>>&&>>&&>>&&>>&正文
原生Js实现简易烟花爆炸效果的方法教程
本文实例讲述了原生Js实现简易烟花爆炸效果的方法。分享给大家供大家参考。具体分析如下:
实现原理: 在一定范围内,随机生成一些div,形成烟花效果
代码如下:&!doctype html&
&meta charset="utf-8"&
&title&js烟花效果&/title&
&script type="text/javascript"&
document.onclick=function (ev)
&&& var oEvent=ev||
&&& var aDiv=[];
&&& var oDiv=
&&& var _oDiv=document.createElement('div');
&&& var i=0;
&&& var x=oEvent.clientX;
&&& var y=oEvent.clientY;
&&& _oDiv.style.position='absolute';
&&& _oDiv.style.background='red';
&&& _oDiv.style.width='3px';
&&& _oDiv.style.height='30px';
&&& _oDiv.style.left=oEvent.clientX+'px';
&&& _oDiv.style.top=document.documentElement.clientHeight+'px';
&&& document.body.appendChild(_oDiv);
&&& var t=setInterval(function (){
&&&&&&& if(_oDiv.offsetTop&=y)
&&&&&&&&&&& clearInterval(t);
&&&&&&&&&&& show();
&&&&&&&&&&& document.body.removeChild(_oDiv);
&&&&&&& _oDiv.style.top=_oDiv.offsetTop-30+'px';
&&& }, 30);
&&& function show()
&&&&&&& var oDiv=
&&&&&&& for(i=0;i&100;i++)
&&&&&&&&&&& oDiv=document.createElement('div');
&&&&&&&&&&& oDiv.style.width='3px';
&&&&&&&&&&& oDiv.style.height='3px';
&&&&&&&&&&& oDiv.style.background='#'+Math.ceil(Math.random()*0xEFFFFF+0x0FFFFF).toString(16);
&&&&&&&&&&& oDiv.style.position='absolute';
&&&&&&&&&&& oDiv.style.left=x+'px';
&&&&&&&&&&& oDiv.style.top=y+'px';
&&&&&&&&&&& var a=Math.random()*360;
&&&&&&&&&&& //oDiv.speedX=Math.random()*40-20;
&&&&&&&&&&& //oDiv.speedY=Math.random()*40-20;
&&&&&&&&&&& oDiv.speedX=Math.sin(a*180/Math.PI)*20*Math.random();
&&&&&&&&&&& oDiv.speedY=Math.cos(a*180/Math.PI)*20*Math.random();
&&&&&&&&&&& document.body.appendChild(oDiv);
&&&&&&&&&&& aDiv.push(oDiv);
&&& setInterval(doMove, 30);
&&& function doMove()
&&&&&&& for(i=0;i&aDiv.i++)
&&&&&&&&&&& aDiv[i].style.left=aDiv[i].offsetLeft+aDiv[i].speedX+'px';
&&&&&&&&&&& aDiv[i].style.top=aDiv[i].offsetTop+aDiv[i].speedY+'px';
&&&&&&&&&&& aDiv[i].speedY+=1;
&&&&&&&&&&& if(aDiv[i].offsetLeft&0 || aDiv[i].offsetLeft&document.documentElement.clientWidth || aDiv[i].offsetTop&0 || aDiv[i].offsetTop&document.documentElement.clientHeight)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& document.body.removeChild(aDiv[i]);
&&&&&&&&&&&&&&& aDiv.splice(i, 1);
&&&&&&&&&&& }
&body style="overflow: background:"&
希望本文所述对大家的javascript程序设计有所帮助。
转载请注明:破洛洛(谢谢合作)
上一篇文章: 下一篇文章:
网友评论:
[][][][][][][][][][]一个js的问题,。麻烦各位棒棒忙。谢谢_百度知道
一个js的问题,。麻烦各位棒棒忙。谢谢
0'javascript".offsetTop-20+'html&style'UTF-8&css&style&
oDiv.createElement(&px' 20.toString(16).style.clientHeight+'
body{4px'div1&
oDiv.createElement('.
div{position.div id=".width='/.height='&body>.width=': absolute.background=',30);/+;
for (var i = 0;
oDstyle type=&&
var t=oE&#'
aD/2px'.top=oD;script&显示oDiv.offsetTop-20+'
} } &/.left=oEvent。代码错误提示是Cannot read property 'div".clientX;px';
timer=setInterval(function(){
oDiv:div' &.length&;& &;&>.offsetTop&30px'.
};/.random()*);>.top=oDiv.clientX+'/ <.background='script type=&/).appendChild(oDiv).clientY. <.
oD+getRnd();
oDiv!DOCTYPE html>.style.left=l+'px'.height='px'.title&text/body>./.这条代码有错误;
function getRnd(){
var str=M);title>. &6){
srt='.push(oDiv); i <.
document.removeChild(oDiv);<.ceil(M;&
oDiv.documentEpx'&red'&
} &/;;html lang=&2px'
var timer=
oDiv: hidden&div>.meta charset=&
var aDiv=[]. i++) {
var oDiv=px'alert(str)./
while(text/head>.onclick=function(ev){
var oEvent=ev||event.appendChild(oDiv).top=t+'.top==t){
clearInterval(timer);&en&<
为什么会报错?
0'javascript".offsetTop-20+'html&style'UTF-8&css&style&
oDiv.createElement(&px' 20.toString(16).style.clientHeight+'
body{4px'div1&
oDiv.createElement('.
div{position.div id=".width='/.height='&body>.width=': absolute.background=',30);/+;
for (var i = 0;
oDstyle type=&&
var t=oE&#'
aD/2px'.top=oD;script&显示oDiv.offsetTop-20+'
} } &/.left=oEvent。代码错误提示是Cannot read property 'div".clientX;px';
timer=setInterval(function(){
oDiv:div' &.length&;& &;&>.offsetTop&30px'.
};/.random()*);>.top=oDiv.clientX+'/ <.background='script type=&/).appendChild(oDiv).clientY. <.
oD+getRnd();
oDiv!DOCTYPE html>.style.left=l+'px'.height='px'.title&text/body>./.这条代码有错误;
function getRnd(){
var str=M);title>. &6){
srt='.push(oDiv); i <.
document.removeChild(oDiv);<.ceil(M;&
oDiv.documentEpx'&red'&
} &/;;html lang=&2px'
var timer=
oDiv: hidden&div>.meta charset=&
var aDiv=[]. i++) {
var oDiv=px'alert(str)./
while(text/head>.onclick=function(ev){
var oEvent=ev||event.appendChild(oDiv).top=t+'.top==t){
clearInterval(timer);&en&<
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁小伙伴出错了原生Js实现简易烟花爆炸效果的方法
本文实例讲述了原生Js实现简易烟花爆炸效果的方法。分享给大家供大家参考。具体分析如下:
实现原理: 在一定范围内,随机生成一些div,形成烟花效果
&!doctype html&
&meta charset=”utf-8″&
&title&js烟花效果&/title&
&script type=”text/javascript”&
document.onclick=function (ev)
&&& var oEvent=ev||
&&& var aDiv=[];
&&& var oDiv=
&&& var _oDiv=document.createElement(‘div’);
&&& var i=0;
&&& var x=oEvent.clientX;
&&& var y=oEvent.clientY;
&&& _oDiv.style.position=’absolute’;
&&& _oDiv.style.background=’red’;
&&& _oDiv.style.width=’3px’;
&&& _oDiv.style.height=’30px’;
&&& _oDiv.style.left=oEvent.clientX+’px’;
&&& _oDiv.style.top=document.documentElement.clientHeight+’px’;
&&& document.body.appendChild(_oDiv);
&&& var t=setInterval(function (){
&&&&&&& if(_oDiv.offsetTop&=y)
&&&&&&&&&&& clearInterval(t);
&&&&&&&&&&& show();
&&&&&&&&&&& document.body.removeChild(_oDiv);
&&&&&&& _oDiv.style.top=_oDiv.offsetTop-30+’px’;
&&& }, 30);
&&& function show()
&&&&&&& var oDiv=
&&&&&&& for(i=0;i&100;i++)
&&&&&&&&&&& oDiv=document.createElement(‘div’);
&&&&&&&&&&& oDiv.style.width=’3px’;
&&&&&&&&&&& oDiv.style.height=’3px’;
&&&&&&&&&&& oDiv.style.background=’#’+Math.ceil(Math.random()*0xEFFFFF+0x0FFFFF).toString(16);
&&&&&&&&&&& oDiv.style.position=’absolute’;
&&&&&&&&&&& oDiv.style.left=x+’px’;
&&&&&&&&&&& oDiv.style.top=y+’px’;
&&&&&&&&&&& var a=Math.random()*360;
&&&&&&&&&&& //oDiv.speedX=Math.random()*40-20;
&&&&&&&&&&& //oDiv.speedY=Math.random()*40-20;
&&&&&&&&&&& oDiv.speedX=Math.sin(a*180/Math.PI)*20*Math.random();
&&&&&&&&&&& oDiv.speedY=Math.cos(a*180/Math.PI)*20*Math.random();
&&&&&&&&&&& document.body.appendChild(oDiv);
&&&&&&&&&&& aDiv.push(oDiv);
&&& setInterval(doMove, 30);
&&& function doMove()
&&&&&&& for(i=0;i&aDiv.i++)
&&&&&&&&&&& aDiv[i].style.left=aDiv[i].offsetLeft+aDiv[i].speedX+’px’;
&&&&&&&&&&& aDiv[i].style.top=aDiv[i].offsetTop+aDiv[i].speedY+’px’;
&&&&&&&&&&& aDiv[i].speedY+=1;
&&&&&&&&&&& if(aDiv[i].offsetLeft&0 || aDiv[i].offsetLeft&document.documentElement.clientWidth || aDiv[i].offsetTop&0 || aDiv[i].offsetTop&document.documentElement.clientHeight)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& document.body.removeChild(aDiv[i]);
&&&&&&&&&&&&&&& aDiv.splice(i, 1);
&&&&&&&&&&& }
&body style=”overflow: background:”&
希望本文所述对大家的javascript程序设计有所帮助。
相关文章:
暂时还没有评论.