myfucntion
= 5秒后发送请求
document.ready(myfucntion)
$(window).focus(myfucntion)
$(window).blur(stop(myfucntion))
这可能会停止在document.ready
之前调用的模糊函数答案 0 :(得分:1)
拥有全球计时器:
var intervalId;
最好有两个功能:
startfunction() {
intervalId = setTimeout(function () {
// send request after 5 seconds
}, 5000);
}
stopfunction() {
clearTimeout(intervalId);
}
并像这样使用它们:
$(document).ready(startfunction);
$(document).ready(function () {
$(window).focus(startfunction);
$(window).blur(stopfunction);
});
答案 1 :(得分:0)
以下是如何制作您想要的作品
的示例var timer; // make it global so it can be accessed inside functions
var myFunction = function () {
timer = setTimeout(function() {
//do something after 5 seconds
}, 5000);
}
var stopMyFunction = function () {
clearTimeout(timer);
}
$(document).ready(myFunction)
$(window).focus(myFunction)
$(window).blur(stopMyFunction))