国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

JS實現放煙花效果

瀏覽:83日期:2024-05-19 18:05:51

本文實例為大家分享了JS實現放煙花效果的具體代碼,供大家參考,具體內容如下

<!DOCTYPE html><html> <head> <meta charset='UTF-8'> <title>放煙花——欣欣博客</title> <style> html,body{overflow:hidden;} body,div,p{margin:0;padding:0;} body{background:#000;font:12px/1.5 arial;color:#7A7A7A;} .fire { width: 3px; height: 30px; background: white; position: absolute; } .spark { position: absolute; width: 6px; height: 6px; } </style> <script src='http://www.cgvv.com.cn/bcjs/move.js'></script> <script> οnlοad=function(){ document.οnclick=function(e){ e =e||event; var coord ={ x:e.clientX, y:e.clientY }; new Fire(coord).init().launch(); } function Fire(coord){ var self = this; //初始化 this.init=function(){ this.ball = document.createElement('div'); this.ball.className='fire'; this.ball.style.left = coord.x+'px'; this.ball.style.top= window.innerHeight +'px'; document.body.appendChild(this.ball); return this; } //發射 this.launch=function(){ animate(this.ball,{left:coord.x,top:coord.y,height:3},{callback:function(){ self.explode(); }}); return this; } //爆炸 this.explode=function(){ this.destory(); var count = randomInt(30,50); for(var i =0;i<count;i++){ new Spark(coord).init().parabola(); } } //銷毀 this.destory = function(){ this.ball.remove(); } } function Spark(coord){ var self = this; this.init=function(){ this.box = document.createElement('div'); this.box.className='spark'; this.box.style.backgroundColor='#'+randomColor(); console.log(this.box.style.backgroundColor) this.box.style.left = coord.x+'px'; this.box.style.top = coord.y+'px'; this.box.speedX = randomInt(-20,20); this.box.speedY = randomInt(-20,10); document.body.appendChild(this.box); return this; } this.parabola=function(){ this.timer =setInterval(function(){ if(self.box.offsetTop >window.innerHeight){ clearInterval(self.timer); self.destroy(); return; } self.box.style.left = self.box.offsetLeft + self.box.speedX +'px'; self.box.style.top = self.box.offsetTop +self.box.speedY++ +'px'; },30) } this.destory=function(){ this.box.remove(); } } //隨機整數 function randomInt(min,max){ return Math.round(Math.random()*(max-min)+min); } //隨機顏色 function randomColor(){ var R = Math.round( Math.random()*255 ).toString(16); var G = Math.round( Math.random()*255 ).toString(16); var B = Math.round( Math.random()*255 ).toString(16); return (R.length<2?'0'+R:R) + (G.length<2?'0'+G:G)+ (B.length<2?'0'+B:B); } } </script> </head> <body> </body></html>

move.js

/** * * @param {Object} obj 目標對象 * @param {Object} json 要改變的屬性 * @param {Object} extend {buffer,callback} 當buffer為true時為彈性運動 * callback會在運動結束時,被執行 * animate(obj, {top:500, left: 300}, {callback:function(){}, buffer: true}) */function animate(obj, json, extend){ extend = extend || {}; if(obj.isMoving){ return; } else { stop(); obj.isMoving = true; } //obj = Object.assgin(obj,extend); obj.buffer = extend.buffer; obj.callback = extend.callback; obj.timerlist = {}; //為每一個屬性添加一個定時器 for(var attr in json){ (function(attr){ obj.timerlist[attr] = {speed:0}; obj.timerlist[attr].timer = setInterval(function(){ //首先得到當前值 var iNow = 0; if(attr == 'opacity'){ iNow = getStyle(obj, attr) * 100; } else { iNow = getStyle(obj, attr); } var speed = obj.timerlist[attr].speed; //根據目標值,計算需要的速度 if(obj.buffer==true){ speed += (json[attr] - iNow)/5; speed *= 0.75; } else { speed = (json[attr] - iNow)/5; } //當無限接近目標值時,停止定時器 if(Math.abs(iNow - json[attr]) < 0.5){ clearInterval(obj.timerlist[attr].timer); delete obj.timerlist[attr]; if(getObjLength(obj.timerlist)==0){//所有定時器已停止 stop(); obj.callback ? obj.callback() : ''; } } else { //根據速度,修改當前值 if(attr == 'opacity'){ obj.style.opacity = (iNow+speed)/100; obj.style.filter = ’alpha(opacity=’ + parseFloat(iNow+speed) + ’)’; } else { obj.style[attr] = iNow+speed+'px'; } obj.timerlist[attr].speed = speed; } }, 30); })(attr); } function clearTimer(){ for(var i in obj.timerlist){ clearInterval(obj.timerlist[i]); } } function getStyle(obj, attr){ if(obj.currentStyle){ return isNaN(parseFloat(obj.currentStyle[attr])) ? obj.style[attr]=0 : parseFloat(obj.currentStyle[attr]); } else { return isNaN(parseFloat(getComputedStyle(obj, null)[attr])) ? obj.style[attr]=0 : parseFloat(getComputedStyle(obj, null)[attr]); } } function getObjLength(obj){ var n = 0; for(var i in obj){ n++; } return n; } function stop(){ clearTimer();//清除所有定時器 obj.isMoving = false; }}

更多JavaScript精彩特效分享給大家:

Javascript菜單特效大全

javascript仿QQ特效匯總

JavaScript時鐘特效匯總

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 偷拍自拍日韩 | 99av在线 | 国产特黄一级一片免费 | 亚洲国产天堂在线网址 | a级片在线观看免费 | 午夜国产视频 | 精品久久久久久久高清 | 99在线观看精品免费99 | 欧美孕交视频 | 中文字幕一二三区乱码老 | 成人在线网址 | 成人免费精品视频 | 国产精品色综合久久 | 国产1000部成人免费视频 | 国产精品秒播无毒不卡 | 特色黄色片 | 131美女爱做免费毛片 | 国产一级免费视频 | 国产三级精品在线观看 | 欧美成人性做爰 | 成人欧美一级毛片免费观看 | 久久88香港三级台湾三级中文 | 久久精品香蕉视频 | 亚洲91在线| 国产在线a不卡免费视频 | 97欧美精品一区二区三区 | 男女扒开双腿猛进入免费网站 | 手机看片欧美 | 成人三级网址 | 美女扒开腿让男人桶个爽 | 特级毛片a级毛免费播放 | 亚洲日本高清 | 亚洲美女精品视频 | 亚洲一级特黄特黄的大片 | 美女网站视频黄色 | 久久国产精品二区99 | 国产精品区一区二区免费 | 99久久免费国产香蕉麻豆 | 午夜67194| 国产精品免费看久久久香蕉 | 18在线观看国内精品视频 |