Skip to content

Instantly share code, notes, and snippets.

@mandelbro
Created November 13, 2012 19:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mandelbro/4067903 to your computer and use it in GitHub Desktop.
Save mandelbro/4067903 to your computer and use it in GitHub Desktop.
Quick jQuery plugin to get the duration of a CSS transition for an element
(function( $ ) {
/**
* jQuery.transtionend
* Retrievs the total amount of time, in miliseconds that
* an element will be transitioned
*/
$.fn.transtionend = function() {
// check the main transition duration property
if(this.css('transition-duration')) {
return Math.round(parseFloat(this.css('transition-duration')) * 1000);
}
else {
// check the vendor transition duration properties
if(this.css('-webkit-transtion-duration')) return Math.round(parseFloat(this.css('-webkit-transtion-duration')) * 1000);
if(this.css('-moz-transtion-duration')) return Math.round(parseFloat(this.css('-moz-transtion-duration')) * 1000);
if(this.css('-ms-transtion-duration')) return Math.round(parseFloat(this.css('-ms-transtion-duration')) * 1000);
if(this.css('-o-transtion-duration')) return Math.round(parseFloat(this.css('-ms-transtion-duration')) * 1000);
}
// if we're here, then no transition duration was found, return 0
return 0;
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment