I want to play or pause video on scroll, if scroll is greater than 300 it should pause otherwise it should play. This is my video tag
<video width="100%" controls >
<source src="video.mp4" type="video/mp4" >
</video>
And the Jquery
$(document).ready(function(){
var scroll = $(window).scrollTop();
if(scroll > 300){
$('video').attr('autoplay':'false')
}
else{
$('video').attr('autoplay':'true')
}
})
Now I'm not using autoplay attr directly. Please help me how can I fix this ?
Edit :
i updated my code to this
$(document).ready(function(){
$(window).scroll(function(){
var scroll = $(window).scrollTop();
if(scroll > 300){
$('#videoId').get(0).pause() ;
}
else{
$('#videoId').get(0).play();
}
})
})
still does not work