A video autoplays on page load, and when it's finished the page automatically scrolls down to the main content container.
When a user either clicks the scroll-down button, or scrolls the page manually, I need this automatic scroll to be cancelled.
I've got the autoscroll part working. I'm struggling with stopping it happening if the user interacts.
https://codepen.io/alexconnor/pen/bGbYgda
function scrollToMain() {
$('html, body').animate({
scrollTop: ($('#main-content-container').offset().top)
}, 2000);
}
$('#homepage-video').on('ended', function() {
scrollToMain();
});
$('.arrow-scroll-down').click(function() {
$('#homepage-video').off('ended', function() {
scrollToMain();
});
scrollToMain();
});
$(window).scroll(function() {
$('#homepage-video').off('ended', function() {
scrollToMain();
});
});
#video-container,
#main-content-container {
height: calc(100vh);
}
.arrow-scroll-down {
font-size: 28px
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="video-container">
<video id="homepage-video" class="hp-video__video" tabindex="0" autobuffer="autobuffer" preload="preload" muted autoplay>
<source src="https://v.ftcdn.net/01/93/01/28/700_F_193012896_tKFDpztvreS9PTlqINL2STlk2oxkr7na_ST.mp4" type="video/mp4; codecs="avc1.42E01E, mp4a.40.2"">
</video>
<div class="arrow animated bounce">
<a href="#" class="arrow-scroll-down"><i class="fas fa-chevron-down"></i></a><br />
</div>
</div>
<div id="main-content-container">
<h1>Main Content Container</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>