广告位联系
返回顶部
分享到

JS实现的小火箭发射动画效果的教程

JavaScript 来源:转载 作者:秩名 发布时间:2018-12-10 09:23:25 人浏览
摘要

本篇文章给大家分享JS实现的小火箭发射动画效果的教程。 代码如下: !DOCTYPE htmlhtml lang=enhead meta charset=UTF-8 title小火箭发射/title style type=text/css *{ margin: 0px; padding: 0px; } .big{ width: 500px; height: 600px; border: 1px solid

本篇文章给大家分享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>





版权声明 : 本文内容来源于互联网或用户自行发布贡献,该文观点仅代表原作者本人。本站仅提供信息存储空间服务和不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权, 违法违规的内容, 请发送邮件至2530232025#qq.cn(#换@)举报,一经查实,本站将立刻删除。
原文链接 :
相关文章
  • 本站所有内容来源于互联网或用户自行发布,本站仅提供信息存储空间服务,不拥有版权,不承担法律责任。如有侵犯您的权益,请您联系站长处理!
  • Copyright © 2017-2022 F11.CN All Rights Reserved. F11站长开发者网 版权所有 | 苏ICP备2022031554号-1 | 51LA统计