-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (35 loc) · 1.11 KB
/
script.js
File metadata and controls
40 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const animated = document.querySelectorAll(
'[data-animate], [data-pop], .card, .feature__media video, .card video'
);
const observer = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
if (entry.target.tagName === 'VIDEO') {
entry.target.play().catch(() => {});
}
}
});
},
{ threshold: 0.35 }
);
animated.forEach(el => observer.observe(el));
const toggleButtons = document.querySelectorAll('.play-toggle');
toggleButtons.forEach(button => {
const video = button.previousElementSibling;
button.addEventListener('click', () => {
if (video.paused) {
video.play();
button.querySelector('span').textContent = 'pause';
} else {
video.pause();
button.querySelector('span').textContent = 'play';
}
});
});
const cards = document.querySelectorAll('.card video');
cards.forEach(video => {
video.addEventListener('mouseenter', () => video.play());
video.addEventListener('mouseleave', () => video.pause());
});