diff --git a/velocity.js b/velocity.js index ddbc64bd..88412164 100644 --- a/velocity.js +++ b/velocity.js @@ -3582,7 +3582,7 @@ devices to avoid wasting battery power on inactive tabs. */ /* Note: Tab focus detection doesn't work on older versions of IE, but that's okay since they don't support rAF to begin with. */ if (!Velocity.State.isMobile && document.hidden !== undefined) { - document.addEventListener("visibilitychange", function() { + var updateTicker = function() { /* Reassign the rAF function (which the global tick() function uses) based on the tab's focus state. */ if (document.hidden) { ticker = function(callback) { @@ -3597,7 +3597,13 @@ } else { ticker = window.requestAnimationFrame || rAFShim; } - }); + }; + + /* Page could be sitting in the background at this time (i.e. opened as new tab) so making sure we use correct ticker from the start */ + updateTicker(); + + /* And then run check again every time visibility changes */ + document.addEventListener("visibilitychange", updateTicker); } /************