Skip to content

Commit

Permalink
Select correct ticker function during initialization (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwasawafag authored and Rycochet committed Dec 2, 2016
1 parent 7255f4c commit 579c4d7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions velocity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

/************
Expand Down

0 comments on commit 579c4d7

Please sign in to comment.