I'm building an HTML5 video as background which plays with the mouse wheel like this excellent example.
Now I want to enhance it by pausing it while still scrolling then start to play it again after I've scrolled for a certain amount. I've tried but the problem is that it jumps on the point where it supposed to be if I hadn't paused it rather than continuing from where I've paused.
Here's my code:
$(function () {
var vid = $('#v0')[0]; // jquery option
// pause video on load
vid.pause();
// pause video on document scroll (stops autoplay once scroll started)
window.onscroll = function () {
vid.pause();
//console.log(vid.currentTime, window.pageYOffset / 400);
$("#time").text(vid.currentTime);
};
// refresh video frames on interval for smoother playback
setInterval(function () {
if((window.pageYOffset / 400) > 3 && (window.pageYOffset / 400) < 6){
vid.pause();
} else {
vid.currentTime = window.pageYOffset / 400;
}
}, 32);
});
Is there a way of achieving that?
Thanks