Created
November 13, 2012 19:40
-
-
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
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
(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