jquery 實現撒金幣效果

來源:互聯網
上載者:User

[html]  html>  <head>  <title></title>  <style type="text/css">  body{padding:0px;margin:0px;font-size:12px;overflow:hidden;background:#000;}  #container div{padding:10px;position:absolute;border:0px dotted brown;width:0px;color:#FF0000;cursor:pointer;}  .text{padding:10px;color:#ccc;}  </style>    <script type="text/javascript" src="http://www.cozof.com/images/js/jquery.min.1.5.js"></script>  <script type="text/javascript">  var goldFallInterval;  var goldFallStart=0;  function initGoldFall(){      var length = $('div','#container').length;            if(length<4){          for(i=0;i<6;i++){           $('div','#container').clone().prependTo('#container');          }      }        }  function startGoldFall(){      clearInterval(goldFallInterval);      endCount = 0;      range();      goldFallStart = new Date().getTime();      goldFallInterval= setInterval(dropGoldFall,200);  }    //排列  function range()  {   var num = 1;   $('div','#container').each(function(i)   {    var ww = $(window).width();//視窗寬度    var wh = $(window).height();      var ot = -20;//從頭部以上開始      $(this).css({"left":(i*(ww/64)) +"px","top":"-50px"});//距左距離保持,距上距離變化    num ++;   });  }    //降落  function dropGoldFall()  {      var now =  new Date().getTime();      if(now - goldFallStart >3000){                    clearInterval(goldFallInterval);      }   var $objs =  $('div','#container');   $objs.each(function(i)   {    var wh   = $(window).height();    var ol   = $(this).offset().left;    var ot   = $(this).offset().top;    var rnd  = Math.round(Math.random()*100);    var rnd2 = Math.round(Math.random()*50);       //降落的速度    if(ot<=wh)//如果掉到視窗以下    {          $(this).css({"top":(ot+rnd+rnd2) +"px"});    }   });  }      function fn(){      initGoldFall();      startGoldFall();  }  </script>  </head>  <body>  <!--begin-->  <div id="container">  <div><img src=image/gold.png ></div>  </div>    woafdasfasfdasfsadfasfasf<input type=button onclick="fn();" value=test>  <!--end-->    </body>  <script language="javascript">    </script>  </html>    問題描述HTML5遊戲中過關希望實現撒金幣效果,最開始通過canvas寫了幾個簡單的隨機函數繪製金幣,發現效果不行。通過收索發現有jquery實現的下雪效果:  希望更換雪片的貼圖,後發現jquery的幾個下雪模型都是使用  '&#10052;' 這個符號來實現的,所以無法更換貼圖。最終參考了  中的代碼實現了一個簡單的。  實現代碼  自己準備金幣的圖片,直接運行。 通過調用一下代碼,可多次啟動。[html]  initGoldFall();  startGoldFall();   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.