简体   繁体   English

切换到另一个选项卡时animationend不起作用

[英]animationend not working when switched to another tab

I have this JavaScript: 我有这个JavaScript:

$(function(){
    var aE = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
    $('.animate').one(aE, function(){
        alert('Animation End !!!');
    });
});

It works okay when my tab is in the foreground. 当我的标签页位于前台时,它可以正常工作。 But when I switch to another tab, it pauses. 但是当我切换到另一个选项卡时,它会暂停。 If I switch back to my tab, it will resume working then show the alert. 如果我切换回我的标签,它将恢复工作,然后显示警报。

I want my handler to fire even when I have another tab active. 我希望我的处理程序即使在我激活了另一个标签时也能触发。

To me it looks wise that the browsers pause the frontend processing when a tab is inactive: frames, timers, etc.. 对我来说,明智的做法是,当选项卡(框架,计时器等)处于不活动状态时,浏览器暂停前端处理。

In my opinion if you need to do something at the end of an animation and the exact time matters for you, you need to rethink it completely, you can't rely on those events / animations / timers. 在我看来,如果您需要在动画结束时做点什么,而确切的时间对您来说很重要,那么您需要完全重新考虑它,您不能依赖那些事件/动画/计时器。

Maybe webworkers if it can suit your needs ? 也许网络工作者是否可以满足您的需求?

https://jsfiddle.net/23rgtotc/3/ console.log('start', new Date()); https://jsfiddle.net/23rgtotc/3/ console.log('start', new Date());

The above example / log shows that the time when the event is triggered is when you get back to the tab, not just 5 seconds after. 上面的示例/日志显示,触发事件的时间是返回到选项卡的时间,而不仅仅是5秒之后。

https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame

requestAnimationFrame() calls are paused in most browsers when running in background tabs or hidden s in order to improve performance and battery life. 在大多数浏览器中,在后台选项卡或隐藏的s中运行时,requestAnimationFrame()调用会暂停,以提高性能和电池寿命。

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

To reduce the load (and associated battery usage) from background tabs, timeouts are throttled to firing no more often than once per second (1000 ms) in inactive tabs. 为了减少后台选项卡的负载(和相关的电池使用量),在不活动的选项卡中,将超时限制为每秒触发一次(1000毫秒)以上。

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

相关问题 切换选项卡时,jQuery SlideDown不起作用 - JQuery SlideDown isn't working when switched tab webkitAnimationEnd msAnimationEnd animationend不起作用 - webkitAnimationEnd msAnimationEnd animationend not working animationend在递归函数中不起作用 - animationend not working in recursive function 切换到新标签页时,内容显示在当前标签页的div下面 - Content appears below the div of the current tab when switched to new tab "当标签空闲或在另一个选项卡上工作时,setInterval停止工作," - Setinterval is stop working when tab is idle or working on another tab, Typed.js 文本动画在浏览器选项卡切换时暂停 - Typed.js text animation pauses when browser tab switched 切换浏览器选项卡时隐藏小程序的JDialog - Hide JDialog of applet when browser's tab is switched 动画真正结束时不会触发Animationend事件 - Animationend event not firing when animation really ends 当浏览器选项卡最小化或在选项卡之间切换时需要停止计时器倒计时 - Need To stop Timer counting down when browser tab minimized or been switched between tabs echarts打开tab时,容器宽度设置为100%,但是不管怎么设置,宽度都只有100px - When echarts is switched on tab, the container width is set to 100%, but no matter how it is set, the width is only 100px
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM