Last active
February 26, 2025 15:00
-
-
Save yoriiis/3bfd3833d5aaaa454c682f782b1e3a23 to your computer and use it in GitHub Desktop.
Get CSS transition duration in second or millisecond
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| header { | |
| transition-duration: 250ms; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this snippet!