clearTimeout(timer) 后如何重新启动另一个函数?
我在 7 秒不活动(没有 mousemove 事件)后停止了 refreshTable() 函数。客户端在不活动后移动鼠标时是否可以重新启动刷新?
如果可能的话,我想保留最上面的函数 refreshTable()。
//====DONT EDIT THIS FUNCTION IF POSSIBLE====
function refreshTable() {
window.clearTimeout(timer);
timer = window.setTimeout(refreshTable, 5000);
$("body").append("<p>refreshTable every 5 seconds.</p>");
}
//========
var timer = window.setTimeout(refreshTable, 0);
// If theres no activity for 7 seconds do something
var activityTimeout = setTimeout(clientInActive, 7000);
function clientResetActive(){
$("body").attr('class', 'active');
clearTimeout(activityTimeout);
activityTimeout = setTimeout(clientInActive, 5000);
//RESTART TIMER WHILE resetActive
//????????
}
// No activity do something.
function clientInActive(){
$("body").attr('class', 'clientInactive');
$("body").append("<p>clientInActive</p>");
//STOP TIMER WHILE clientInActive
clearTimeout(timer);
}
// Check for mousemove, could add other events here such as checking for key presses ect.
$(document).bind('mousemove', function(){clientResetActive()});
目标如下图所示。