Issue: I'm attempting to have a YouTube video auto-play when the user scrolls to it and stops when the user scrolls past it.
Constraints: New to JavaScript web development.
Tried: Going off of https://jsfiddle.net/kmsdev/gsfkL6xL/ I copy pasted line for line just to get it to work. I'm familiar with C++ and Java so I can at least read the main points of the code. It seems that I have the code correct but I might not be calling it correctly within my HTML5?
Hero Section:
<section class="video_background">
<div class="video_foreground">
<iframe id="playerA" frameborder="0" title="YouTube video player" type="text/html" src="https://www.youtube.com/embed/u1zgFlCw8Aw?enablejsapi=1"></iframe>
</div>
</section>
JS Section:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/scroll.js"></script>
JS:
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
I have this on top of https://jsfiddle.net/kmsdev/gsfkL6xL/ but that shouldn't matter.