Skip to content

Instantly share code, notes, and snippets.

@aduth
Created May 8, 2013 20:08
Show Gist options
  • Save aduth/5543247 to your computer and use it in GitHub Desktop.
Save aduth/5543247 to your computer and use it in GitHub Desktop.
Convert CSS3 transition duration string to milliseconds
var transitionDurationToMilliseconds = function(duration) {
var pieces = duration.match(/^([\d\.]+)(\w+)$/),
time, unit, multiplier;
if (pieces.length <= 1) {
return duration;
}
time = pieces[1];
unit = pieces[2];
switch(unit) {
case 'ms': multiplier = 1; break;
case 's': multiplier = 1000; break;
}
return time * multiplier;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment