亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JS實(shí)現(xiàn)放煙花效果

 更新時(shí)間:2020年03月10日 13:59:41   作者:玉米_欣  
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)放煙花效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了JS實(shí)現(xiàn)放煙花效果的具體代碼,供大家參考,具體內(nèi)容如下

<!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="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;
  }
  //發(fā)射
  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();
  }
  
  
 }
 
 //隨機(jī)整數(shù)
 function randomInt(min,max){
  return Math.round(Math.random()*(max-min)+min);
 }
 //隨機(jī)顏色
 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 目標(biāo)對(duì)象
 * @param {Object} json 要改變的屬性
 * @param {Object} extend {buffer,callback} 當(dāng)buffer為true時(shí)為彈性運(yùn)動(dòng)
 * callback會(huì)在運(yùn)動(dòng)結(jié)束時(shí),被執(zhí)行
 * 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 = {};
 //為每一個(gè)屬性添加一個(gè)定時(shí)器
 for(var attr in json){
 (function(attr){
 obj.timerlist[attr] = {speed:0};
 obj.timerlist[attr].timer = setInterval(function(){
 //首先得到當(dāng)前值
 var iNow = 0;
 if(attr == "opacity"){
  iNow = getStyle(obj, attr) * 100; 
 } else {
  iNow = getStyle(obj, attr);
 }
 var speed = obj.timerlist[attr].speed;
 //根據(jù)目標(biāo)值,計(jì)算需要的速度
 if(obj.buffer==true){
  speed += (json[attr] - iNow)/5;
  speed *= 0.75;
 } else {
  speed = (json[attr] - iNow)/5;
 }
 //當(dāng)無限接近目標(biāo)值時(shí),停止定時(shí)器
 if(Math.abs(iNow - json[attr]) < 0.5){
  clearInterval(obj.timerlist[attr].timer);
  delete obj.timerlist[attr];
  if(getObjLength(obj.timerlist)==0){//所有定時(shí)器已停止
  stop();
  obj.callback ? obj.callback() : "";
  }
 } else {
  //根據(jù)速度,修改當(dāng)前值
  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();//清除所有定時(shí)器
 obj.isMoving = false;
 }
}

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

Javascript菜單特效大全

javascript仿QQ特效匯總

JavaScript時(shí)鐘特效匯總

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JS異步的執(zhí)行順序分析

    JS異步的執(zhí)行順序分析

    這篇文章介紹了JS異步的執(zhí)行順序,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • JS數(shù)組的高級(jí)使用方法示例小結(jié)

    JS數(shù)組的高級(jí)使用方法示例小結(jié)

    這篇文章主要介紹了JS數(shù)組的高級(jí)使用方法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript數(shù)組的增刪改查、排序、隨機(jī)數(shù)等相關(guān)操作技巧,需要的朋友可以參考下
    2020-03-03
  • 小程序?qū)崿F(xiàn)搜索框

    小程序?qū)崿F(xiàn)搜索框

    搜索框無論是在電商網(wǎng)站還是小程序中都很常見,這篇文章主要就為大家詳細(xì)介紹了小程序如何實(shí)現(xiàn)搜索框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • js 字符串轉(zhuǎn)換成數(shù)字的三種方法

    js 字符串轉(zhuǎn)換成數(shù)字的三種方法

    在js讀取文本框或者其它表單數(shù)據(jù)的時(shí)候獲得的值是字符串類型的,例如兩個(gè)文本框a和b,如果獲得a的value值為11,b的value值為9 ,那么a.value要小于b.value,因?yàn)樗麄兌际亲址问降?在網(wǎng)上找了一下js字符串轉(zhuǎn)數(shù)字的文章,這個(gè)比較全
    2013-03-03
  • JS通過位運(yùn)算實(shí)現(xiàn)權(quán)限加解密

    JS通過位運(yùn)算實(shí)現(xiàn)權(quán)限加解密

    這篇文章主要介紹了JS通過位運(yùn)算實(shí)現(xiàn)權(quán)限加解密的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2018-08-08
  • js判斷60秒以及倒計(jì)時(shí)示例代碼

    js判斷60秒以及倒計(jì)時(shí)示例代碼

    本篇文章主要是對(duì)js判斷60秒以及倒計(jì)時(shí)的示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助
    2014-01-01
  • JavaScript精煉之構(gòu)造函數(shù) Constructor及Constructor屬性詳解

    JavaScript精煉之構(gòu)造函數(shù) Constructor及Constructor屬性詳解

    對(duì)象的constructor屬性用于返回創(chuàng)建該對(duì)象的函數(shù),也就是我們常說的構(gòu)造函數(shù),除了創(chuàng)建對(duì)象,構(gòu)造函數(shù)(constructor) 還做了另一件有用的事情—自動(dòng)為創(chuàng)建的新對(duì)象設(shè)置了原型對(duì)象(prototype object)
    2015-11-11
  • 25個(gè)讓你眼前一亮的JavaScript代碼技巧分享

    25個(gè)讓你眼前一亮的JavaScript代碼技巧分享

    學(xué)習(xí)強(qiáng)大的JavaScript一行代碼,能夠節(jié)省你的時(shí)間和代碼量,所以本文為大家整理了25個(gè)JavaScript實(shí)用代碼技巧,感興趣的小伙伴可以了解一下
    2023-07-07
  • JavaScript設(shè)計(jì)模式之中介者模式詳解

    JavaScript設(shè)計(jì)模式之中介者模式詳解

    當(dāng)對(duì)象之間進(jìn)行多對(duì)多引用時(shí),進(jìn)行開發(fā),維護(hù),閱讀時(shí)將變得特別痛苦。在這些對(duì)象之間添加中間者,使它們都只與中介者,當(dāng)中介者處理完一個(gè)對(duì)象的請(qǐng)求后,將結(jié)果通知于其他對(duì)象
    2022-08-08
  • Z-Blog中用到的js代碼

    Z-Blog中用到的js代碼

    Z-Blog中用到的js代碼...
    2007-03-03

最新評(píng)論