이렇게해야합니다. 당신은 당신의 필요에 적응할 수 있어야합니다. 나는 본질적으로 당신이 링크 한 SO 문제의 코드를 복사했다. 이렇게하면 활성/비활성 클래스가 본문에 추가됩니다. 내 코드를 실행할 때 이것을 볼 수 있습니다. 페이지가 활성화되면 화면이 파란색입니다. 이는 새로 고침이 수행되었음을 나타냅니다. 화면이 회색이면 상쾌하게하지 마십시오.
그런 다음 코드에 활성/비활성 클래스 검사를 입력하면됩니다.
http://jsfiddle.net/scgEs/1
var refreshrate = 4000;
var inactivitytime = 15000;
var refreshid; //set to global scope so that you can clear it later
var activityTimeoutId; //store timeout for inactivity
$('#sbox').slideUp();
$('#toggle').click(function() {
$('#sbox').slideDown('fast');
refreshId = setInterval(function() {
if ($('body.inactive').length == 1) {
$('#sbox').append('<div>No refresh</div>');
}
else {
console.log('Refreshing data');
$('#sbox').append('<div>Refreshed...</div>');
//$('#shout').load('shout.php?randval=' + Math.random());
}
}, refreshrate);
return false;
});
// If theres no activity for X seconds do something
activityTimeoutId = setTimeout(inActive, inactivitytime);
function resetActive() {
$(document.body).attr('class', 'active');
clearTimeout(activityTimeoutId);
activityTimeoutId = setTimeout(inActive, inactivitytime);
}
// No activity do something.
function inActive() {
$(document.body).attr('class', 'inactive');
}
// Check for mousemove, could add other events here such as checking for key presses ect.
$(document).bind('mousemove', function() {
resetActive()
});
방금 내 대답을 업데이트했습니다. 내 변수를 대체하는 것을 잊었습니다. – mrtsherman
감사합니다 mrtsherman, 내 자신의 요구 (분명히)에 맞게 조정할 필요가 있었지만 응답으로 표시된 것은 잘 작동합니다.) –