Reputation: 2029
Actually I just want to put this as a kind of Wiki, after breaking my fingers on this.
Anyway, posting answer below:
Upvotes: 1
Views: 1324
Reputation: 2029
So - A straight forward, shortest solution is for creating a video on an html page, or indeed use a "raw HTML" element in WordPress:
<script type="text/javascript">
var video = null;
var ended = false;
function checkScroll()
{
if( video == null )
return;
var rect = video.getBoundingClientRect();
// console.log( rect.top, rect.bottom, window.innerHeight, document.documentElement.clientHeight );
var inViewPort = Math.abs( rect.top ) < window.innerHeight;
if( inViewPort )
{
if( video.paused && ( ended == false ) )
{
video.play();
video.addEventListener( 'ended', myHandler, false );
function myHandler(e)
{
ended = true;
}
}
}
else
{
video.currentTime = 0;
ended = false;
}
}
window.onload = function()
{
video = document.getElementById( 'rubi-second-video' );
window.onscroll = function()
{
checkScroll();
}
}
checkScroll();
Upvotes: 1