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

jquery實(shí)現(xiàn)煙花效果(面向?qū)ο?

 更新時(shí)間:2020年03月10日 15:53:07   作者:-恩恩-  
這篇文章主要為大家詳細(xì)介紹了jquery面向?qū)ο髮?shí)現(xiàn)煙花效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>煙花效果(面向?qū)ο?</title>
 <style type="text/css">
  *{padding: 0;margin: 0}
  body{overflow: hidden;width: 100%;height: 100%;background: #000; }
  div{position: absolute;background: #000;color: #fff}
 </style>
 <script src="jquery-1.8.3.min.js"></script></script>


</head>

<body>
<script type="text/javascript">
 var firWorks = {
  init : function(){ //初始化
   var _that = this;
    $(document).bind("click",function(e){
    _that.eventLeft = e.pageX;
    _that.eventTop = e.pageY;
    _that.createCylinder();
    });
  },
  createCylinder : function(event){ //創(chuàng)建一個(gè)花筒
   var _that = this;
   this.cHeight = document.documentElement.clientHeight;//瀏覽器高度
   this.cylinder = $("<div/>");
   $("body").append(this.cylinder);
   this.cylinder.css({"width":4,"height":15,"background-color":"red","top":this.cHeight,"left":this.eventLeft});
   this.cylinder.animate({top:this.eventTop},600,function(){
    $(this).remove();
    _that.createFlower();
   })
  },
  createFlower : function(){ //創(chuàng)建很多很多的煙花哇?。?
   /*煙花效果
   *1.煙花是很多個(gè)DIV構(gòu)成
   *2.每個(gè)煙花的顏色不一樣
   *3.煙花的位置也不一樣
   *4.煙花散開方向不一樣
   *5.煙花有下墜感覺
   */
   //通過循環(huán)可以創(chuàng)建你想要的煙花啦?。?!
   var _that = this;
   for(var i = 0 ; i < 30; i++ ){
    $("body").append($("<div class='flower'></div>"));
   };
   $(".flower").css({"width":3,"height":3,"top":this.eventTop,"left":this.eventLeft});
   $(".flower").each(function(index, element) {
    var $this = $(this);
    var yhX = Math.random()*400-200;
    var yhY = Math.random()*600-300;
    _that.changeColor();
    $this.css({"background-color":"#"+_that.randomColor,"width":3,"height":3}).animate({"top":_that.eventTop-yhY,"left":_that.eventLeft-yhX},500);//散開
    for(var i=0;i<30;i++){
     //判斷鼠標(biāo)點(diǎn)擊時(shí)的右邊煙花還是左邊煙花
     if(yhX<0){
      _that.downPw($this,"+");//右下墜
     }else{
      _that.downPw($this,"-");//左下墜
     }
    }
   });     
  },
  changeColor : function(){
   /*煙花的顏色是隨機(jī)的,而且是用16進(jìn)制表示色值,所以用隨機(jī)數(shù)結(jié)合16進(jìn)制;
   *16進(jìn)制的最大值ffffff,轉(zhuǎn)換成十進(jìn)制16777215;
   *Math.random()*16777215公式可以得到0-16777215之間的數(shù),因?yàn)槭切?shù),所以要用到取整;
   *Math.ceil(Math.random()*16777215)生成一個(gè)在顏色值范圍內(nèi)的,隨機(jī)的十進(jìn)制值;
   *Math.random()*9+1公式可以得到1-10之間的數(shù),以此類推
   *.toString(16)方法,是把得到的十進(jìn)制,轉(zhuǎn)換成16進(jìn)制,也就是隨機(jī)的顏色值了;
   */    
   this.randomColor = "";
   this.randomColor = Math.ceil(Math.random()*16777215).toString(16)//;
   //當(dāng)這個(gè)產(chǎn)生的隨機(jī)的顏色值,不足6位數(shù)的進(jìn)候,需要補(bǔ)齊,又不改變其值,所以要在這個(gè)數(shù)的前面加零;
   while(this.randomColor.length<6){
    this.randomColor = "0"+this.randomColor;
   }
  },
  downPw : function(ele,type){ //煙花下墜啦 ?。。?!
   ele.animate({"top":"+=30","left":type+"=4"},50,function(){
     setTimeout(function(){ele.remove()},2000);
   })
  }
 };
 firWorks.init();
</script>

</body>
</html>

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

jQuery幻燈片特效匯總

jQuery焦點(diǎn)圖特效匯總

jQuery級(jí)聯(lián)菜單特效匯總

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

相關(guān)文章

最新評(píng)論