I have a JavaScript function that pauses a video when it reaches 5 seconds.
<video id="home-hero-video" preload autoplay="autoplay" muted="muted">
<source src="videourl.mp4" type="video/mp4">
</video>
The video automatically starts playing and stops at the 5-second mark using an event listener.
var video = document.getElementById('home-hero-video');
video.addEventListener("timeupdate", function () {
if (this.currentTime >= 5.000) {
this.pause();
}
}, false);
I want the video to resume playing from the 5-second mark to the end when scrolling down.
var scrollableElement = document.body;
scrollableElement.addEventListener('wheel', checkScrollDirection);
function checkScrollDirection(event) {
if (checkScrollDirectionIsUp(event)) {
// console.log('scroll UP');
} else {
video.removeEventListener("timeupdate");
video.play();
}
}