Skip to content

Instantly share code, notes, and snippets.

@yoosefi
Last active July 21, 2016 09:53
Show Gist options
  • Save yoosefi/170a9521e5eb7f38229aa706a8d5a690 to your computer and use it in GitHub Desktop.
Save yoosefi/170a9521e5eb7f38229aa706a8d5a690 to your computer and use it in GitHub Desktop.
Makes HTML5 videos answer clicks and refresh their thumbnails like YouTube does.
// developer console will mess with this (window.innerHeight). close it.
$(function(){
$('video').on('ended',function(){
// reload thumbnail
this.autoplay = false;
this.load();
}).on('click',function(){
// if no double click, change play state
var innerHeight = window.innerHeight;
var that = this;
setTimeout(function(){
if (window.innerHeight == innerHeight) {
that.paused && that.play() || that.pause();
}
},300);
}).on('dblclick',function(){
// exit fullscreen
if (window.innerHeight == screen.height) {
var exitFs = document.exitFullscreen
|| document.webkitExitFullscreen
|| document.mozExitFullscreen
|| document.msExitFullscreen;
exitFs.call(document);
return;
}
// enter fullscreen
var enterFs = this.requestFullscreen
|| this.webkitRequestFullscreen
|| this.mozRequestFullScreen
|| this.msRequestFullscreen;
enterFs.call(this);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment