Reputation: 53
I would like to stop my jquery animation when I open new tab in browser. Every time when I leave my page for a while and I come back after some time, my jquery slider goes crazy and it change slides like insane, because I didn't stop it. Do you have some solution?
Upvotes: 1
Views: 2195
Reputation: 19492
In JavaScript:
window.addEventListener('focus', function() {
// code to start
});
window.addEventListener('blur', function() {
// code to stop
});
With jQUery:
$(window).bind('focus', function() {
// code to start
});
$(window).bind('blur', function() {
// code to stop
});
Upvotes: 8
Reputation: 20193
I read somewhere about this and it's called animation queue buildup. Instead of trying to stop animation when opening new tab, put stop()
just before starting an animation.
This will ensure that previous animation is killed before continuing....
for example:
$('.some-selector').stop().slideUp();
Hope this helps...
Upvotes: 3