Skip to content

Commit efea939

Browse files
authored
Refactor video animation and toggle functionality
1 parent 9a3722d commit efea939

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

script.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
const animated = document.querySelectorAll(
2-
'[data-animate], [data-pop], .card, .feature__media video, .card video'
3-
);
4-
5-
const observer = new IntersectionObserver(
6-
entries => {
7-
entries.forEach(entry => {
8-
if (entry.isIntersecting) {
9-
entry.target.classList.add('is-visible');
10-
if (entry.target.tagName === 'VIDEO') {
11-
entry.target.play().catch(() => {});
12-
}
13-
}
14-
});
15-
},
16-
{ threshold: 0.35 }
17-
);
18-
19-
animated.forEach(el => observer.observe(el));
20-
21-
const toggleButtons = document.querySelectorAll('.play-toggle');
22-
23-
toggleButtons.forEach(button => {
24-
const video = button.previousElementSibling;
25-
button.addEventListener('click', () => {
26-
if (video.paused) {
27-
video.play();
28-
button.querySelector('span').textContent = 'pause';
29-
} else {
30-
video.pause();
31-
button.querySelector('span').textContent = 'play';
32-
}
33-
});
34-
});
35-
36-
const cards = document.querySelectorAll('.card video');
37-
cards.forEach(video => {
38-
video.addEventListener('mouseenter', () => video.play());
39-
video.addEventListener('mouseleave', () => video.pause());
1+
const animated = document.querySelectorAll(
2+
'[data-animate], [data-pop], .card, .feature__media video, .card video'
3+
);
4+
5+
const observer = new IntersectionObserver(
6+
entries => {
7+
entries.forEach(entry => {
8+
if (entry.isIntersecting) {
9+
entry.target.classList.add('is-visible');
10+
if (entry.target.tagName === 'VIDEO') {
11+
entry.target.play().catch(() => {});
12+
}
13+
}
14+
});
15+
},
16+
{ threshold: 0.35 }
17+
);
18+
19+
animated.forEach(el => observer.observe(el));
20+
21+
const toggleButtons = document.querySelectorAll('.play-toggle');
22+
23+
toggleButtons.forEach(button => {
24+
const video = button.previousElementSibling;
25+
button.addEventListener('click', () => {
26+
if (video.paused) {
27+
video.play();
28+
button.querySelector('span').textContent = 'pause';
29+
} else {
30+
video.pause();
31+
button.querySelector('span').textContent = 'play';
32+
}
33+
});
34+
});
35+
36+
const cards = document.querySelectorAll('.card video');
37+
cards.forEach(video => {
38+
video.addEventListener('mouseenter', () => video.play());
39+
video.addEventListener('mouseleave', () => video.pause());
4040
});

0 commit comments

Comments
 (0)