开发者社区> 问答> 正文

js计时器 定时刷新不活动的页面,若页面活动,则不刷新

设置30秒页面刷新,若鼠标移到时,计时器停止。若不移到,则30秒刷新一次

有没有详细的实现方式

展开
收起
a123456678 2016-07-08 15:27:52 2390 0
1 条回答
写回答
取消 提交回答
  • <style>
       #test{width: 200px;height: 200px;background-color: grey;opacity: 0.5}
    </style>
    <script src="http://code.jquery.com/jquery-2.0.3.js"></script>
     
     
    <body>
        <div id="test"></div>
    </body>
    <script type="text/javascript">
     
    var timeLen=3*1000*10;
    var timer=setInterval(function(){
        console.log("refresh");
    },timeLen);
    $("#test").mouseover(function(){
        clearInterval(timer);
        console.log("stop");
    }).mouseout(function(){
        timer=setInterval(function(){
           console.log("refresh");
        },timeLen);
    });
    </script>
    2019-07-17 19:53:30
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
JavaScript异步编程 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载