简体   繁体   English

当浏览器选项卡未聚焦时,Javascript setInterval / setTimeout不起作用

[英]Javascript setInterval/setTimeout not working when browser tab not focused

So I'm modifying a Highcharts piechart trying to execute the following: 因此,我正在修改Highcharts饼图,以尝试执行以下操作:

function updateAngle( lastAngle ) {
    if ($("#container").highcharts() != null && $("#container").highcharts() != undefined) {
        var currentAngle = lastAngle;
        var destinationAngle = getAngle();
        if (currentAngle != destinationAngle) {
            currentAngle += 1;
            if (currentAngle > destinationAngle) {
                currentAngle = destinationAngle;
            }
            $("#container").highcharts().get('Series').update({
                endAngle: currentAngle
            });
            setTimeout(updateAngle, 1, currentAngle);
        }
    }
}

After each interation I'm adding 1 to the previous angle, now I've read that setInterval/setTimeout doesn't work with browsers when tabbed out due to it not requesting animation. 每次交互后,我都将1加到前一个角度,现在我读到setInterval / setTimeout在跳出时不支持浏览器,因为它不请求动画。 I've read that ".queue" is a function that can work for me, but I'm unsure how to convert my setTimeout method to using .queue. 我已经读过“ .queue”是一个可以为我工作的函数,但是我不确定如何将setTimeout方法转换为使用.queue。

Timeouts are clamped to firing no more often than once per second (1000 ms) in inactive tabs, but they still fire. 在不活动的标签页中,超时的触发频率不超过每秒触发一次(1000 ms),但仍会触发。 You won't have any issue with your code. 您的代码不会有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript:setTimeout(setInterval)无法正常工作 - JavaScript: setTimeout (setInterval) not working JavaScript setInterval()和setTimeout()冻结浏览器 - JavaScript setInterval() and setTimeout() freezing browser 如何知道浏览器选项卡是否在加载Javascript时关注? - How to know if a browser tab focused when it's loaded with Javascript? JavaScript 函数 setTimeout() 和 setInterval() 有时不起作用 - JavaScript functions setTimeout() and setInterval() are sometimes not working 为什么有 setTimeout 和 setInterval 时 javascript 没有睡眠功能? - Why there is no sleep functionality in javascript when there is setTimeout and setInterval? jQuery-如果浏览器标签集中,则执行AJAX-不起作用 - jQuery - If browser tab is focused, then do AJAX - Not working javascript settimeout或setinterval函数何时停止? - When does a javascript settimeout or setinterval function stop? 在JavaScript中使用setTimeout()和setInterval()时调用函数 - Calling a function when using setTimeout() and setInterval() in JavaScript 异步JavaScript轮询使用setTimeout或setInterval冻结浏览器 - Asynchronous JavaScript polling freezes the browser using setTimeout or setInterval 了解JavaScript setTimeout和setInterval - Understanding JavaScript setTimeout and setInterval
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM