Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.