定时器图片高亮从中间往两边循环

5 篇文章 0 订阅

效果图:

页面代码:


<style> *, :after, :before { margin: 0; padding: 0; box-sizing: border-box; } * { margin: 0; padding: 0; } table { border-spacing: 0; border-collapse: collapse; text-align: center; } .draw { width: 560px; height: 600px; margin: 0 auto; padding:51px; background-image: url(images/bg.png); background-repeat: no-repeat; background-size: 100%; } .draw .item { width: 150px; height: 150px; background-image: url(images/bg1.png); background-repeat: no-repeat; background-size: 96%; } .draw .item.active { background-image: url(images/bg2.png); background-repeat: no-repeat; background-size: 100%; } .draw .img { display: table-cell; width: 150px; height: 61px; vertical-align: middle; text-align: center; } .draw .img img { vertical-align: top; } .draw .gap { width: 5px; } .draw .gap-2 { height: 5px; } </style>

<!--布局除table外也可用ul>li-->
<body style="background: #f02d2f;">
   <div class="draw" id="lottery">
      <table>
         <tr>
            <td class="item lottery-unit lottery-unit-2">
               <div class="img">
                  <img src="images/img1.png" alt="">
               </div>
            </td>
            <td class="gap"></td>
            <td class="item lottery-unit lottery-unit-1">
               <div class="img">
                  <img src="images/img2.png" alt="">
               </div>
            </td>
            <td class="gap"></td>
            <td class="item lottery-unit lottery-unit-2">
               <div class="img">
                  <img src="images/img3.png" alt="">
               </div>
            </td>
         </tr>
         <tr>
            <td class="gap-2" colspan="5"></td>
         </tr>
         <tr>
            <td class="item lottery-unit lottery-unit-3">
               <div class="img">
                  <img src="images/img4.png" alt="">
               </div>
            </td>
            <td class="gap"></td>
            <td class="item lottery-unit lottery-unit-0">
               <div class="img">
                  <img src="images/img5.png" alt="">
               </div>
            </td>
            <td class="gap"></td>
            <td class="item lottery-unit lottery-unit-3">
               <div class="img">
                  <img src="images/img5.png" alt="">
               </div>
            </td>
         </tr>
         <tr>
            <td class="gap-2" colspan="5"></td>
         </tr>
         <tr>
            <td class="item lottery-unit lottery-unit-4">
               <div class="img">
                  <img src="images/img7.png" alt="">
               </div>
            </td>
            <td class="gap"></td>
            <td class="item lottery-unit lottery-unit-5">
               <div class="img">
                  <img src="images/img6.png" alt="">
               </div>
            </td>
            <td class="gap"></td>
            <td class="item lottery-unit lottery-unit-4">
               <div class="img">
                  <img src="images/img8.png" alt="">
               </div>
            </td>
         </tr>
      </table>
   </div>
<script src="js/jquery-2.2.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
   var lottery = {
      index: 0, //当前转动到哪个位置,起点位置
      count: 0, //总共有多少个位置
      timer: 0,
      init: function(id) {
         if($('#' + id).find('.lottery-unit').length >= 0) {
            $lottery = $('#' + id);
            $units = $lottery.find('.lottery-unit');
            this.obj = $lottery;
            this.count = $units.length;
            $lottery.find('.lottery-unit.lottery-unit-' + this.index).addClass('active');
         };
      },
      roll: function() {
         var index = this.index;
         var count = this.count;
         var lottery = this.obj;
         $(lottery).find('.lottery-unit.lottery-unit-' + index).removeClass('active');
         index += 1;
         if(index >=  count) {
            index = 0;
         }
         this.index = index;
         $(lottery).find('.lottery-unit.lottery-unit-' + index).addClass('active');
         return false;
      },
   };
   window.onload = function() {
      lottery.init('lottery');
      var ref=null;
      ref=setInterval(function(){
            lottery.times += 1;
            lottery.roll();

                lottery.times = 0;
                return false;
      },300)
   };
</script>
</body>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值