Skip to content

Commit 332699f

Browse files
committed
Play feature grid items on hover
1 parent 6feebc4 commit 332699f

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

static/js/video-playback.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ function setupPlayer(video) {
22
const container = document.createElement('div');
33
const icon = document.createElement('div');
44

5+
const play = () => {
6+
const promise = video.play();
7+
8+
container.classList.remove('paused');
9+
10+
promise?.catch(() => {
11+
container.classList.add('paused');
12+
});
13+
};
14+
15+
const pause = () => {
16+
video.pause();
17+
container.classList.add('paused');
18+
};
19+
520
video.parentNode.insertBefore(container, video);
621

722
icon.classList.add('video-player-icon');
@@ -10,15 +25,28 @@ function setupPlayer(video) {
1025
container.appendChild(video);
1126
container.appendChild(icon);
1227

13-
container.addEventListener('click', () => {
14-
if (video.paused) {
15-
video.play();
16-
container.classList.remove('paused');
17-
} else {
18-
video.pause();
19-
container.classList.add('paused');
20-
}
21-
});
28+
const feature = video.closest('.feature-grid li');
29+
30+
if (feature != null) {
31+
video.removeAttribute('loop');
32+
video.loop = false;
33+
34+
feature.addEventListener('mouseenter', () => {
35+
video.loop = true;
36+
37+
play();
38+
});
39+
40+
feature.addEventListener('mouseleave', pause);
41+
} else {
42+
container.addEventListener('click', () => {
43+
if (video.paused) {
44+
play();
45+
} else {
46+
pause();
47+
}
48+
});
49+
}
2250

2351
container.style.borderRadius = window.getComputedStyle(video).borderRadius;
2452

0 commit comments

Comments
 (0)