reset homepage video timestamp when out of frame

This commit is contained in:
outfoxxed 2026-04-02 23:10:26 -07:00
parent 3ce5f46c3b
commit 8af645c093
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -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();