gpt4 book ai didi

javascript - jquery onscreen run offscreen 暂停

转载 作者:行者123 更新时间:2023-11-29 15:50:43 25 4
gpt4 key购买 nike

当有人离开页面但没有查看它时,是否有办法暂停长轮询脚本?因此,如果我打开应用程序的多个选项卡或窗口,只有我正在查看的那个才会运行事件的长轮询脚本?

最佳答案

实际上,在 javascript 中没有暂停脚本的有效方法。但让我提出一个建议:

function pausecomp(millis){

var date = new Date();
var curDate = null;

do{
curDate = new Date();
}while(curDate-date < millis);
}

所以这会暂停整个脚本数毫秒。然而,这不是一个好的做法。

Javascript 允许设置事件在延迟后发生:

setTimeout("alert('hello')",1250);

因此,当到达这行代码时,setTimeout 方法会在经过 1250 毫秒时调用警报。

希望这些信息对您有所帮助;)


为了检测鼠标何时离开窗口,我为您设置了一个 jsfiddle:http://jsfiddle.net/xPAwu/1/

此外,在 stackoverflow 上实际上还有一些问题:How can I detect when the mouse leaves the window?

Javascript event when mouse leaves browser window

关于javascript - jquery onscreen run offscreen 暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5859344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com