Skip to content

Commit 9faf667

Browse files
committed
Fade in videos after load
1 parent f6ad79b commit 9faf667

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

docusaurus.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export default {
1616
projectName: 'react-navigation.github.io',
1717
onBrokenAnchors: 'throw',
1818
onBrokenMarkdownLinks: 'throw',
19-
scripts: ['/js/snack-helpers.js', '/js/toc-fixes.js'],
19+
scripts: [
20+
'/js/snack-helpers.js',
21+
'/js/toc-fixes.js',
22+
'/js/video-playback.js',
23+
],
2024
themeConfig: {
2125
colorMode: {
2226
defaultMode: 'light',

static/js/video-playback.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function fadeInOnLoad(video) {
2+
if (video.readyState >= 3) {
3+
video.style.transition = 'opacity 1s';
4+
video.style.opacity = '1';
5+
} else {
6+
video.style.transition = 'opacity 1s';
7+
video.style.opacity = '0';
8+
9+
video.addEventListener('canplaythrough', () => {
10+
video.style.opacity = '1';
11+
});
12+
}
13+
}
14+
15+
document.addEventListener('DOMContentLoaded', () => {
16+
const observer = new MutationObserver(() => {
17+
const videos = document.querySelectorAll('video');
18+
19+
videos.forEach((video) => {
20+
if (video.dataset.seen) {
21+
return;
22+
}
23+
24+
video.dataset.seen = true;
25+
26+
if (video.hasAttribute('playsinline')) {
27+
video.addEventListener('click', () => {
28+
if (video.paused) {
29+
video.play();
30+
} else {
31+
video.pause();
32+
}
33+
});
34+
}
35+
36+
fadeInOnLoad(video);
37+
});
38+
});
39+
40+
observer.observe(document.documentElement, {
41+
childList: true,
42+
subtree: true,
43+
});
44+
});
45+
46+
console.log('Video playback script loaded');

0 commit comments

Comments
 (0)