Last active
July 21, 2016 09:53
-
-
Save yoosefi/170a9521e5eb7f38229aa706a8d5a690 to your computer and use it in GitHub Desktop.
Makes HTML5 videos answer clicks and refresh their thumbnails like YouTube does.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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