Skip to content

Instantly share code, notes, and snippets.

@snorpey
Created April 5, 2013 22:06
Show Gist options
  • Save snorpey/5323028 to your computer and use it in GitHub Desktop.
Save snorpey/5323028 to your computer and use it in GitHub Desktop.
get css transition duration of DOM element.
// 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