Skip to content

Instantly share code, notes, and snippets.

@dryan
Created September 21, 2010 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dryan/589133 to your computer and use it in GitHub Desktop.
Save dryan/589133 to your computer and use it in GitHub Desktop.
function getElementTransitionDuration(elem, property) {
// this currently only supports Webkit browsers, but should be easy enough to apply to others as they begin to support CSS transitions
var td = elem ? window.getComputedStyle(elem)['-webkit-transition-duration'].split(', ') : [],
tp = elem ? window.getComputedStyle(elem)['-webkit-transition-property'].split(', ') : [],
durations = {},
longest = 0,
i = td.length;
while( --i ) {
var dur = parseFloat(td[i], 10);
if(i < tp.length) {
durations[tp[i]] = dur;
}
longest = dur > longest ? dur : longest;
}
if(!property) {
return longest;
} else if(durations[property]) {
return durations[property];
} else {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment