add parseDuration method

This commit is contained in:
Cory LaViska
2021-05-26 12:41:52 -04:00
parent 8776c3f4a8
commit 3fce846a8d

View File

@@ -18,6 +18,23 @@ export function animateTo(el: HTMLElement, keyframes: Keyframe[], options?: Keyf
});
}
//
// Parses a CSS duration and returns the number of milliseconds.
//
export function parseDuration(delay: number | string) {
delay = (delay + '').toLowerCase();
if (delay.indexOf('ms') > -1) {
return parseFloat(delay);
}
if (delay.indexOf('s') > -1) {
return parseFloat(delay) * 1000;
}
return parseFloat(delay);
}
//
// Tells if the user has enabled the "reduced motion" setting in their browser or OS.
//