-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Customizing animation repeat count and animation duration with utilities #17659
rozsazoltan
started this conversation in
Show and tell
-
Update
After understanding the implementation of variables, you can familiarize yourself with the animation-iteration-count
and animation-duration
property, which has been part of the baseline since 2015.
animate-repeat-*
andanimate-duration-*
with CSS variablesanimate-repeat-*
andanimate-duration-*
with CSS animation properties- CSS:
animation-iteration-count
- MDN Docs - CSS:
animation-duration
- MDN Docs
@import "tailwindcss"; /* Utility for Animation Timing */ @utility animate-duration-* { animation-duration: --value([*]); animation-duration: calc(--value(integer) * 1s); } /* Utility for Repeat Count */ @utility animate-repeat-* { animation-iteration-count: --value(integer, 'infinite', [*]); }
Original Code
The other day, I created utilities for customizing the repeat count and timing of any animation. I’ll leave them here in case they are useful for someone else:
In the final solution, I was assisted by Wongjn's answer. The default animations can be overridden by using @theme inline
instead of @theme
to declare the animation. This doesn’t add any extra overhead if the animations used are already part of the project, as they will end up being part of the compiled CSS anyway.
Utility for Repeat Count - animate-repeat-*
@utility animate-repeat-* { --animate-bounce-count: --value(integer); } @utility animate-repeat-infinite { --animate-bounce-count: infinite; }
Utility for Animation Timing - animate-duration-*
@utility animate-duration-* { --animate-duration: calc(--value(integer) * 1s); }
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment