Skip to content

Commit cfe60d6

Browse files
committed
fix header animation when loaded in background tab
1 parent edc7ede commit cfe60d6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

website/static/js/headerAnimation.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ document.addEventListener('DOMContentLoaded', () => {
1818
timeouts.push(setTimeout(animateStep, timeout));
1919
}
2020

21-
timeouts.push(
22-
setTimeout(() => {
23-
logo.classList.remove('init');
24-
animateStep();
25-
}, 2000)
26-
);
21+
// only start the animation if the document is visible on load
22+
if (!document.hidden) {
23+
timeouts.push(
24+
setTimeout(() => {
25+
logo.classList.remove('init');
26+
animateStep();
27+
}, 2000)
28+
);
29+
}
2730

2831
// https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
2932
document.addEventListener(
@@ -36,6 +39,7 @@ document.addEventListener('DOMContentLoaded', () => {
3639
// clear the timeouts array
3740
timeouts.length = 0;
3841
} else {
42+
// restart the animation when visible
3943
animateStep();
4044
}
4145
},

0 commit comments

Comments
 (0)