Björn Ewers
Björn Ewers
document.addEventListener("scroll", function() { let video = document.querySelector("#myVideo"); let bounding = video.getBoundingClientRect(); let windowHeight = window.innerHeight; if (bounding.top < windowHeight && bounding.bottom > 0) { // Berechnung: Wieviel Prozent des Scrollbereichs sind durchlaufen? let scrollFraction = (windowHeight - bounding.top) / (windowHeight + bounding.height); // Begrenzen, damit scrollFraction nicht kleiner als 0 oder größer als 1 wird scrollFraction = Math.max(0, Math.min(1, scrollFraction)); // Weiches Update des Videos mit requestAnimationFrame requestAnimationFrame(() => { video.currentTime = scrollFraction * video.duration; }); } });