Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created March 10, 2016 15:27
Show Gist options
  • Select an option

  • Save Langmans/7b3cffe90468a2d9095e to your computer and use it in GitHub Desktop.

Select an option

Save Langmans/7b3cffe90468a2d9095e to your computer and use it in GitHub Desktop.
add classes to video / audio DOM elements so you can add custom controls.
jQuery(function($){
$('audio,video')
.on('init ended pause play playing progress ratechange seeked seeking stalled suspend waiting', function () {
var obj = this, $obj = $(this);
if ($obj.is('.has-custom-controls')) {
$obj.removeAttr('controls');
}
$.each(['ended', 'error', 'loop', 'muted', 'paused', 'seeking'], function (i, prop) {
try {
var bool = obj[prop];
//console.log(prop, bool);
$obj.toggleClass('is-' + prop, bool);
$obj.toggleClass('not-' + prop, !bool);
} catch (e) {
console.log(e);
}
});
})
.trigger('init');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment