I'm trying to set the currentTime for the html5 video on window scroll event. Basically the idea is to move forward or backward in the video timeline as you scroll the page.
This example here is doing it nicely without a problem: http://codepen.io/ollieRogers/pen/lfeLc
Here is the code:
// select video element
var vid = document.getElementById('v0');
//var vid = $('#v0')[0]; // jquery option
// pause video on load
vid.pause();
// alternative & optimized implementation thanks to http://codepen.io/daveroma/
window.onscroll = function(){
vid.currentTime = window.pageYOffset/400;
};
#set-height
display block
height 13500px
#v0
position fixed
top 0
left 0
width 100%
p font-family helvetica
font-size 24px
<div id="set-height"></div>
<p id="time"></p>
<video id="v0" tabindex="0" autobuffer="autobuffer" preload="preload">
<source type="video/webm; codecs="vp8, vorbis"" src="http://www.html5rocks.com/tutorials/video/basics/Chrome_ImF.webm"></source>
<source type="video/ogg; codecs="theora, vorbis"" src="http://www.html5rocks.com/tutorials/video/basics/Chrome_ImF.ogv"></source>
<source type="video/mp4; codecs="avc1.42E01E, mp4a.40.2"" src="http://www.html5rocks.com/tutorials/video/basics/Chrome_ImF.mp4"></source>
<p>Sorry, your browser does not support the <video> element.</p>
</video>
But when I try it with my own video, the video lags: http://codepen.io/futurecrazy/pen/ZWGYBj
Here is my code:
// select video element
var vid = document.getElementById('v0');
//var vid = $('#v0')[0]; // jquery option
// pause video on load
vid.pause();
// alternative & optimized implementation thanks to http://codepen.io/daveroma/
window.onscroll = function(){
vid.currentTime = window.pageYOffset/400;
};
#set-height
display block
height 13500px
#v0
position fixed
top 0
left 0
width 100%
p font-family helvetica
font-size 24px
<div id="set-height"></div>
<p id="time"></p>
<video id="v0" tabindex="0" autobuffer="autobuffer" preload="preload">
<source type="video/webm" src="http://philippsokolov.com/fm-4.webm"></source>
<source type="video/ogg" src="http://philippsokolov.com/fm-4.ogv"></source>
<source type="video/mp4" src="http://philippsokolov.com/fm-4.m4v"></source>
<p>Sorry, your browser does not support the <video> element.</p>
</video>
I've tried different video compressions but still cant fix the issue.
Would appreciate any help.
/400
in the javascript at the askers code which for me was in a variable called playbackConst – Gil