Play html video while watching it, pause in viewport
I am trying to play my video as soon as it appears in the viewport, and when it no longer appears in the viewport, it should pause.
I've tried this so far:
HTML code:
<video id="video" width="320" height="240" controls>
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4">
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg">
Your browser does not support the video tag.
</video><br>
<video width="320" height="240" controls>
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4">
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg">
Your browser does not support the video tag.
</video>
JQuery code:
$("#video:in-viewport").play();
$(window).scroll(function(){
$("#video:in-viewport").play();
});
I am using this plugin for in-viewport validation
http://www.appelsiini.net/projects/viewport
This is my jsfiddle:
http://jsfiddle.net/hytpm3xe/2/
Does anyone have any idea how to do this correctly?
Thank!
+3
source to share