【简易幸运抽奖】

这是一个【简易幸运抽奖】的代码,欢迎大家前来指导!

<style type="text/css"> //css样式
  .bigbox{
   width:480px;
   height:480px;
   margin: 0 auto;
   
  }
  .box,.box1{
   width:150px;
   height:150px;
   background: skyblue;
   float: left;
   text-align: center;
   margin-right: 10px;
   margin-bottom: 10px;
   line-height: 150px;
   color:white;
  }
  #start{
   width:60px;
   height:25px;
   background: hotpink;
   border: none;
   color: white;
   margin-right: 10px;
  }
  #stop{
   width:60px;
   height:25px;
   background: hotpink;
   border: none;
   color: white;
  }
 </style>

<body>
 <div class="bigbox">
  <div class="box">0</div>
  <div class="box">1</div>
  <div class="box">2</div>
  <div class="box">3</div>
  <div class="box1">
   <button id="start">开始</button>
   <button id="stop" "stop()">停止</button>
  </div>
  <div class="box">4</div>
  <div class="box">5</div>
  <div class="box">6</div>
  <div class="box">7</div>
 </div>
</body>

<script type="text/javascript">
 var box = document.getElementsByClassName("box"); //获取所有的旋转盒子
 // console.log(box);
 var arr = [0,1,2,4,7,6,5,3];  //定义数组根据下标找旋转的位置
 var order = 0;  //从0开始旋转
 var timer = null; //处理bug
 start.onclick = function(){
  clearInterval(timer); //目的是使函数每次都从第一个开始
  timer = setInterval(function(){ //间隔时间函数,0.1秒执行一次;
   var a = arr[order]; //定义a使下标与旋转的盒子对应 
      for (var i = 0; i < box.length; i++) {
       box[i].style.background = "skyblue"; //循环使每个盒子的背景颜色变为初始颜色;
       }
      box[a].style.background = "hotpink"; //当循环到每个盒子时使它变为粉色;
      order++; //每次顺序加1
      if (order == arr.length) { //判断,当顺序循环完一次后,又让它从第一张开始。
       order = 0;
      }
     },100);
    }
   function stop(){
     clearInterval(timer); //当点击停止按钮时,清除时间函数。
     order = 0;
    }
</script>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值