Skip to content

Instantly share code, notes, and snippets.

@yoriiis
Last active February 26, 2025 15:00
Show Gist options
  • Select an option

  • Save yoriiis/3bfd3833d5aaaa454c682f782b1e3a23 to your computer and use it in GitHub Desktop.

Select an option

Save yoriiis/3bfd3833d5aaaa454c682f782b1e3a23 to your computer and use it in GitHub Desktop.
Get CSS transition duration in second or millisecond
function getCSSTransitionDuration ({
element,
ms = false
}) {
return (parseFloat(window.getComputedStyle(element).transitionDuration)) * (ms ? 1000 : 1)
}
getCSSTransitionDuration({
element: document.querySelector('header')
}); //0.25
getCSSTransitionDuration({
element: document.querySelector('header')
ms: true
}); //250
header {
transition-duration: 250ms;
}
@SikuTheNomad

Copy link
Copy Markdown

Thank you for this snippet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment