Created
April 5, 2013 22:06
-
-
Save snorpey/5323028 to your computer and use it in GitHub Desktop.
get css transition duration of DOM element.
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
// jQuery is required for this to work. | |
// based upon this stackoverflow answer: | |
// http://stackoverflow.com/a/13008597 | |
function getTransitionDuration( element, with_delay ) | |
{ | |
var el = $( element ); | |
var prefixes = 'moz webkit ms o khtml'.split( ' ' ); | |
var result = 0; | |
for ( var i = 0; i < prefixes.length; i++ ) | |
{ | |
var duration = el.css( '-' + prefixes[i] + '-transition-duration' ); | |
if ( duration ) | |
{ | |
duration = ( duration.indexOf( 'ms' ) >- 1 ) ? parseFloat( duration ) : parseFloat( duration ) * 1000; | |
if ( with_delay ) | |
{ | |
var delay = el.css( '-' + prefixes[i] + '-transition-delay' ); | |
duration += ( delay.indexOf( 'ms' ) >- 1 ) ? parseFloat( delay ) : parseFloat( delay ) * 1000; | |
} | |
result = duration; | |
break; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment