How are you? I need help to pause the videos that come out of the view when scrolling.
I have already advanced a lot and my code is light, I attach it in case someone serves.
Where I am stuck is in the part of the height, that is, the video starts playing just when it touches the top of the screen but I need it to play about 130px below.
The code I use is:
var vids = document.getElementsByClassName('_makina');
for (var i = vids.length - 1; i >= 0; i--) {
//pause all the videos by default
vids[i].pause();
}
window.onscroll = autoplay;
function autoplay(){
for (var i = vids.length - 1; i >= 0; i--) {
var currentYpos = window.pageYOffset || document.documentElement.scrollTop;
if ( currentYpos >= vids[i].offsetTop && currentYpos <= vids[i].offsetTop + vids[i].offsetHeight ) {
vids[i].play();
}else{
vids[i].pause();
}
}
}
.space {
height: 750px;
background-color:#252525;
color: #fff;
text-align:center;
}
.space2 {
height: 750px;
background-color:#151515;
color: #fff;
text-align:center;
}
.space3 {
height: 750px;
background-color:#dc0031;
color: #fff;
text-align:center;
}
<div class="space"><h3><br><br><br>Desplazate hacia abajo</h3></div>
<video id="myVid" width="100%" autoplay preload class="_makina">
<source type="video/mp4" src="https://makina.com.mx/videos/847692459.mp4" >
</video>
<div class="space2"><br><br><br><h3>Sigue más abajo</h3></div>
<video id="myVid" width="100%" autoplay preload class="_makina">
<source type="video/mp4" src="http://makina.com.mx/videos/847692459.mp4" >
</video>
<div class="space3"><br><br><br><h3>Aquí acabamos</h3></div>
To give you an idea I leave the link that I'm working on, they asked me for something very, very, very similar to FB.
** * EYE: it is not spam, as soon as we find the solution, I will remove it. **
URL: link
That's why I need to reproduce a few pixels below so that the blue bar does not cover it.
I have not been able to move forward for 2 days: (
Greetings and in advance Thank you.