clearTimeout (타이머) 후에 다른 기능을 다시 시작하려면 어떻게해야합니까?clearTimeout (타이머) 후 타이머 다시 시작
7 초 동안 사용하지 않으면 (mousemove 이벤트 없음) refreshTable() 함수가 중지됩니다. 클라이언트가 비활성 상태에서 마우스를 움직이면 새로 고침을 다시 시작할 수 있습니까?
top 함수 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()});
아래 그림과 같은 뭔가가 목표입니다.
당신이 달성하려고하는 일에 대해 조금 더 명확하게 시겠어요, 도와주고 싶어하지만, 당신이 필요로하는 것을 이해하지 않는다! – Eladian
상위 함수 (refreshTable()) 클라이언트가 비활성 상태 일 때 중지/일시 중단하려고합니다. 클라이언트가 돌아올 때 refreshTable()이 다시 시작되거나 계속됩니다. 감사합니다. – Kerry7777
"비활성"은 단어이므로, 낙타의 대소 문자가 도움이되지는 않습니다. IMO를 읽는 것이 조금 힘들어집니다. "IMO를 적극적으로 생각하니?" 'clientInactive'는 더 이해하기 쉬운 변수 이름입니다. – jdgregson