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 e 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?
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 e 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?
Share Improve this question asked Feb 12, 2012 at 1:40 user794596user794596 531 silver badge7 bronze badges 1- Please post a detailed example along with some relevant code. I know you already got your answer but this whole thing will be useless to future readers otherwise. – Sparky Commented Feb 12, 2012 at 2:53
2 Answers
Reset to default 8In 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
});
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...