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>