Skip to content

Instantly share code, notes, and snippets.

@verticalgrain
Created January 5, 2017 17:31
Show Gist options
  • Select an option

  • Save verticalgrain/8efa87faff2c700d4153edd3d8523139 to your computer and use it in GitHub Desktop.

Select an option

Save verticalgrain/8efa87faff2c700d4153edd3d8523139 to your computer and use it in GitHub Desktop.
Manipulate HTML5 video at X seconds from end of video
// Dynamically get the video length, and do something to a video X seconds before it ends
$('.video').on('timeupdate', function(event) {
var timeFromVideoEnd = 2000;
var current = Math.round(event.target.currentTime * 1000);
var total = Math.round(event.target.duration * 1000);
if ( ( total - current ) < timeFromVideoEnd ) {
$body.addClass('fade-video-out');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment