本文介绍了仅在没有鼠标事件时更新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想只在没有鼠标事件时才更新页面,
如:
函数TimedRefresh(t){
$('#colorbox')。mousemove(event){
if(mousemove!= 0){//(mousemove == false)
setTimeout(location .reload(false);,t);
}
}
}
当然不起作用。它被称为:
< body onload =JavaScript:TimedRefresh(5000);>
解决方案
您需要反转逻辑。设置页面的定时器载入,然后在移动鼠标时清除/重新启动它。如果鼠标移动的时间不超过5秒,那么页面将刷新:
$(document).ready(function (){
var timer;
resetTimer();
$ b $('#colorbox')。mousemove(function(){
resetTimer(timer);
$ b函数resetTimer(){
clearTimeout(timer);
timer = setTimeout(function(){
window.location.reload()假);
},5000);
}
}); b
$ b > 工作示例
I would like to update the page only when there are no mouse events,
Such as:
function TimedRefresh(t) {
$('#colorbox').mousemove(event) {
if (mousemove != 0) { //(mousemove == false)
setTimeout("location.reload(false);", t);
}
}
}
It of course does not work. It's called by:
<body onload="JavaScript:TimedRefresh(5000);">
解决方案 You need to reverse the logic. Set the timer onload of the page and then clear/restart it when the mouse is moved. If the mouse is not moved for longer than 5 seconds, then the page will refresh:
$(document).ready(function() {
var timer;
resetTimer();
$('#colorbox').mousemove(function() {
resetTimer(timer);
});
function resetTimer() {
clearTimeout(timer);
timer = setTimeout(function() {
window.location.reload(false);
}, 5000);
}
});
这篇关于仅在没有鼠标事件时更新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!