zoukankan      html  css  js  c++  java
  • 防止定时器的累加

     1 <html lang="en">
     2 <head>
     3     <meta charset="UTF-8">
     4     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     5     <meta http-equiv="X-UA-Compatible" content="ie=edge">
     6     <title>定时器累加</title>
     7      <style>
     8       .box{
     9           width: 100px;
    10           height: 100px;
    11           background-color: red;
    12       }
    13     </style>
    14 </head>
    15 <body>
    16     <div class="box"></div>
    17     <script>
    18     window.onload=function(){
    19         var box = document.getElementsByClassName("box")[0]
    20         var height=0,timer=null;
    21         box.onmouseover=function(){
    22             clearInterval(timer); //清除定时器
    23 
    24             timer=setInterval(function(){
    25              height+=1;
    26              console.log(height)
    27             },1000)
    28         }
    29     }
    30          
    31     </script>
    32 </body>
    33 </html>
    每个你讨厌的现在,都有一个不努力的曾经
  • 相关阅读:
    【图论】第k短路
    【图论】差分约束系统
    【图论】最短路
    【图论】Johnson算法
    HDU5878
    HDU5900
    pow的小事不简单
    math汇总
    Bellman-Ford最短路径
    图的遍历
  • 原文地址:https://www.cnblogs.com/yuanxiangguang/p/11260579.html
Copyright © 2011-2022 走看看