Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript clearTimeout后重新启动计时器(计时器)_Javascript_Jquery_Refresh_Restart_Cleartimeout - Fatal编程技术网

Javascript clearTimeout后重新启动计时器(计时器)

Javascript clearTimeout后重新启动计时器(计时器),javascript,jquery,refresh,restart,cleartimeout,Javascript,Jquery,Refresh,Restart,Cleartimeout,clearTimeout(计时器)后如何重新启动另一个函数 我让refreshTable()函数在7秒不活动(无mousemove事件)后停止。当客户端在不活动后移动鼠标时,是否可以重新启动刷新 顶部函数refreshttable()如果可能,我希望保持原样 /==如果可能,请不要编辑此函数==== 函数刷新表(){ 清除超时(计时器); 定时器=window.setTimeout(刷新表,5000); $(“正文”)。追加(每5秒刷新一次表。); } //======== var timer

clearTimeout(计时器)后如何重新启动另一个函数

我让refreshTable()函数在7秒不活动(无mousemove事件)后停止。当客户端在不活动后移动鼠标时,是否可以重新启动刷新

顶部函数refreshttable()如果可能,我希望保持原样

/==如果可能,请不要编辑此函数====
函数刷新表(){
清除超时(计时器);
定时器=window.setTimeout(刷新表,5000);
$(“正文”)。追加(每5秒刷新一次表。

); } //======== var timer=window.setTimeout(刷新表,0); //如果7秒钟内没有活动,做点什么 var activityTimeout=setTimeout(clientInActive,7000); 函数clientResetActive(){ $(“body”).attr('class','active'); clearTimeout(activityTimeout); activityTimeout=setTimeout(ClientInActivity,5000); //重置激活时重新启动计时器 //???????? } //没有活动做某事。 函数clientInActive(){ $(“body”).attr('class','clientInactive'); $(“正文”)。追加(clientInActive

); //clientInActive时停止计时器 清除超时(计时器); } //检查mousemove,可以在此处添加其他事件,如检查按键等。 $(document.bind('mousemove',function(){clientResetActive()});
下面的图片就是目标


我建议您有一个函数负责启动超时,另一个函数负责停止超时。试试这个:

//==如果可能,请不要编辑此顶部函数====
函数刷新表(){
停止刷新表();
window.refreshtTableTimer=window.setTimeout(refreshtTable,5000);
$(“正文”)。追加(每5秒刷新一次表。

); } //==结束==== 函数startRefreshTable(){ 如果(!window.refreshtTableTimer){ window.refreshtTableTimer=window.setTimeout(refreshtTable,0); } } 函数stopRefreshTable(){ if(窗口刷新表计时器){ self.clearTimeout(window.refreshtTableTimer); } window.refreshtTableTimer=null; } 函数resetActive(){ $(“body”).attr('class','active'); clearTimeout(activityTimeout); activityTimeout=setTimeout(非活动,5000); //重置激活时重新启动计时器 startRefreshTable() } //没有活动做某事。 函数不活动(){ $(“body”).attr('class','inactive'); $(“正文”)。追加(非活动的(); //在不活动时停止计时器 停止刷新表(); } //如果7秒钟内没有活动,做点什么 var activityTimeout=setTimeout(非活动,7000); //检查mousemove,可以在此处添加其他事件,如检查按键等。 $(document.bind('mousemove',function(){resetActive()}); startRefreshTable()
请您更清楚地了解一下您想要实现的目标,想要帮助但不了解您需要什么!当客户端处于非活动状态时,我要停止/挂起的顶部函数(refreshttable())。当客户端(返回)移动鼠标时,refreshTable()将重新启动或继续。谢谢,“不活跃”是一个词,所以我不确定它是否有帮助。这让我读IMO有点困难,因为它让我思考“在一个积极的什么?”
clientInactive
是一个更容易理解的变量名。将变量名更改为clientInactive,感谢您提供名称提示。很好。谢谢你,先生!一个小改动是使activityTimeout=setTimeout(inActive,7000);而不是5000。
//====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()});