reset homepage video timestamp when out of frame
This commit is contained in:
parent
3ce5f46c3b
commit
8af645c093
1 changed files with 21 additions and 4 deletions
|
|
@ -176,12 +176,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
|
||||||
// video handling
|
// video handling
|
||||||
const videos = scroller.querySelectorAll("video");
|
const videos = scroller.querySelectorAll("video");
|
||||||
const observerOptions = {
|
|
||||||
|
const playObserverOptions = {
|
||||||
root: container,
|
root: container,
|
||||||
threshold: 0.5,
|
threshold: 0.5,
|
||||||
};
|
};
|
||||||
|
|
||||||
const videoObserver = new IntersectionObserver(entries => {
|
const playObserver = new IntersectionObserver(entries => {
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
const video = entry.target as HTMLVideoElement;
|
const video = entry.target as HTMLVideoElement;
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
|
|
@ -190,12 +191,28 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
video.pause();
|
video.pause();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, observerOptions);
|
}, playObserverOptions);
|
||||||
|
|
||||||
|
const resetObserverOptions = {
|
||||||
|
root: container,
|
||||||
|
threshold: 0.01,
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetObserver = new IntersectionObserver(entries => {
|
||||||
|
entries.forEach(entry => {
|
||||||
|
const video = entry.target as HTMLVideoElement;
|
||||||
|
if (!entry.isIntersecting) {
|
||||||
|
video.currentTime = 0;
|
||||||
|
video.pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, resetObserverOptions);
|
||||||
|
|
||||||
const startObserving = () => {
|
const startObserving = () => {
|
||||||
const allVideos = scroller.querySelectorAll("video");
|
const allVideos = scroller.querySelectorAll("video");
|
||||||
allVideos.forEach(v => {
|
allVideos.forEach(v => {
|
||||||
videoObserver.observe(v);
|
playObserver.observe(v);
|
||||||
|
resetObserver.observe(v);
|
||||||
v.addEventListener("ended", () => {
|
v.addEventListener("ended", () => {
|
||||||
targetScrollX += itemWidth;
|
targetScrollX += itemWidth;
|
||||||
startAnimation();
|
startAnimation();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue