Javascript setInterval/setTimeout不工作时,浏览器标签不集中

Javascript setInterval/setTimeout not working when browser tab not focused

本文关键字:浏览器 标签 集中 工作 setInterval setTimeout Javascript      更新时间:2023-09-26

所以我正在修改Highcharts piechart,试图执行以下操作:

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);
        }
    }
}

每次交互后,我添加1到前一个角度,现在我已经读到setInterval/setTimeout不工作时,由于它不要求动画的浏览器。我读过。"queue"是一个可以为我工作的函数,但我不确定如何将我的setTimeout方法转换为使用.queue。

在非活动选项卡中,超时被限制为每秒不超过一次(1000毫秒),但它们仍然会触发。你的代码不会有任何问题。