Last active
November 10, 2015 21:25
-
-
Save mhulse/87725fa670412f379980 to your computer and use it in GitHub Desktop.
Simple JavaScript video controller: Click to play and pause HTML5 video tags. Full native video controls show after first play.
This file contains hidden or 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
/** | |
* https://gist.github.com/mhulse/87725fa670412f379980 | |
*/ | |
(function(document) { | |
'use strict'; | |
var i; | |
var $videos = document.querySelectorAll('.simple-video-controler'); | |
var l = $videos.length; | |
var setup = function($video) { | |
$video.addEventListener('play', function() { | |
$video.play(); | |
}, false); | |
$video.onclick = function() { | |
if ($video.paused) { | |
$video.play(); | |
$video.controls = null; | |
} else { | |
$video.pause(); | |
$video.controls = 'controls'; | |
} | |
}; | |
}; | |
if (l) { | |
for (i = 0; i < l; i++) { | |
setup($videos[i]); | |
} | |
} | |
})(document); |
This file contains hidden or 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
/*! https://gist.github.com/mhulse/87725fa670412f379980 */!function(a){"use strict";var b,c=a.querySelectorAll(".simple-video-controler"),d=c.length,e=function(a){a.addEventListener("play",function(){a.play()},!1),a.onclick=function(){a.paused?(a.play(),a.controls=null):(a.pause(),a.controls="controls")}};if(d)for(b=0;d>b;b++)e(c[b])}(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment