本文實例講述了JS實現的小火箭發射動畫效果。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>小火箭發射</title>  <style type="text/css">    *{      margin: 0px;      padding: 0px;    }    .big{      width: 500px;      height: 600px;      border: 1px solid #16283B;      float: left;      position: relative;      background-color: #16283B;    }    .btm{      height: 40px;      width: 100px;      background-color: royalblue;      cursor: pointer;      border: 1px solid blue;      float: left;      position: relative;      top: 560px;      left: 40px;    }    .btm span{      line-height: 40px;      width: 100px;      display: block;      text-align: center;    }    .bt_stop{      height: 40px;      width: 100px;      background-color: royalblue;      cursor: pointer;      border: 1px solid blue;      float: left;      position: relative;      top: 500px;      left: -60px;    }    .bt_stop span{      line-height: 40px;      width: 100px;      display: block;      text-align: center;    }    .rocket{      position: absolute;      bottom: 18px;      left: 180px;    }  </style>  <script type="text/javascript">    // alert("is work!");    //任務1 火箭起飛    //任務2 火箭懸停    var start;    function $(id) {      return document.getElementById(id);    }    function fly() {      start=self.setInterval("fly_do()",10);    }    function start_send() {      alert('start');      fly();    }    function stop() {      //alert('stop');      window.clearInterval(start);    }    function getBottom(rocket) {      var bottomf = rocket.style.bottom;      bottomf = parseInt(bottomf);      if (!bottomf){        bottomf=18;      }      bottomf++;      return bottomf;    }    function fly_do() {      //alert("this is fly");      //通過不斷改變rocket里面的css屬性bottom      //獲取rocket對象      var rocket=$("yingshanhao");      var bottomf=getBottom(rocket);      //改變屬性      rocket.style.bottom=bottomf+"px";      //慢慢飛起來      //js的時間函數    }  </script></head><body>    <div class="big">      <div class="rocket" id="yingshanhao">        <img src="images/rocket1.jpg" style="width: 25%;height:25%;position: relative;left: 40px;bottom: -20px;" >        </div>      </div>      <div class="btm" onmouseover="javascript:stop();" onmouseout="javascript:start_send();">        <span>懸停按鈕</span>      </div>      <div class="bt_stop" onclick="javascript:fly();">        <span>發射按鈕</span>      </div>    </div></body></html>
希望本文所述對大家JavaScript程序設計有所幫助。
新聞熱點
疑難解答