-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add animation support #2068
Add animation support #2068
Conversation
It would be great if the animations could respect the user's |
Agree, and would be good to add support for this to transitions as well. I don't want to block merging this feature on that, but I can look into adding it as a separate feature in the near future. I've read conflicting information about it in my research, so need to study a bit more to figure out what the right approach is. Bootstrap for example respects it on transitions but they don't for loading spinners, and this was a deliberate choice: I think we will probably go with a variant-based solution, where you can do stuff like |
Is it possible to leverage the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Instead of Fade is usually used in animations as a
If users were to extend |
Agree on renaming fade to pulse, done 👍 |
Exciting stuff. Wondering about some sort of fluent interface to build up the config options
|
While I like the idea @dillingham, I think that is very much out of scope for Tailwind. My feeling anyway. |
Added a PR for a new |
👏 |
@adamwathan Is it possible to add "Shake" animation as default animation? theme: {
animation: {
shake: "shake 0.82s cubic-bezier(.36,.07,.19,.97) both",
},
keyframes: {
shake: {
"10%, 90%": { transform: "translate3d(-1px, 0, 0)" },
"20%, 80%": { transform: "translate3d(2px, 0, 0)" },
"30%, 50%, 70%": { transform: "translate3d(-4px, 0, 0)" },
" 40%, 60%": { transform: "translate3d(4px, 0, 0)" },
},
},
}, |
@adamwathan I would love to be able to add animation-delay to the baked in animations. |
^ +1, I find myself extending this quite often via plugin |
@impulse I added a whole bunch in my fancy plugin. https://github.com/brandonpittman/tailwindcss-plugin-fancy/tree/master/packages/animate |
This PR introduces a new
animation
core plugin that generates a set ofanimate-{name}
classes and the correponding@keyframes
declarations.Live demo:
https://tailwind-animation-playground.vercel.app/
It is configured through both the
animation
andkeyframes
sections of yourtailwind.config.js
theme:Animation utilities only include
responsive
variants by default.Design rationale
Targeting the
animation
shorthand propertyOriginally I had planned to implement this feature similar to our transition utilities, where we'd have separate utilities for animation name, duration, timing function, repeat, etc.
I decided against this ultimately because in my explorations I noticed that almost all animations are very specific, and all of the elements of an animation are inherently tightly coupled, making composing animations through several utilities something that is just not that useful in the real world.
Instead I chose to implement this feature by targeting the
animation
shorthand property directly, so every detail of an animation is specified together in one place.This has the added benefit of avoiding any naming collision with the transition utilities.
If someone wanted to create variations of a single animation with the parameters changed, they can just create multiple animations, like
animate-spin
,animate-spin-fast
, andanimate-spin-slow
.Generating utilities and keyframes from a single plugin
You'll notice that the configuration for the
animation
property lives in ananimation
section of the theme, and the@keyframes
definitions live in akeyframes
section, but there is only one core plugin being added (animation
).I considered creating two plugins (
animation
andkeyframes
) but ultimately this felt pedantic. They are always going to be used together and it doesn't add any benefit to control them separately. If anything it would lead to confusion when users disable theanimation
plugin and are surprised when the@keyframes
are still generated. It seemed more aligned with people's expectations to me that they be linked, so I've chosen to generate both from a single plugin, even though it sets a precedent as the first core plugin to read from more than one theme key.I also considered trying to group the
animation
andkeyframes
definitions together using some fancy data structure, but the results also felt unintuitive, and led to other questions that made things feel even more confusing.Example of what I considered but rejected:
Notice how the keyframes can't be named here? Does that mean you leave the name off the animation too, like I have in that example, and have Tailwind add it automatically? Or do you manually add it yourself, knowing it has to match the key name? Too much weird magic, no good.
Included animations
I've chosen to bake in four default animations:
animate-spin
, which is a simple infinite spin, for loading spinners and stuffanimate-ping
, which is a scale/fade animation that looks like a little radar blipanimate-pulse
, which is a subtle opacity pulse, useful for skeleton screensanimate-bounce
, which is a playful bounce, useful for arrows and stuffYou can preview them here:
https://tailwind-animation-playground.vercel.app/
They are all infinite looping animations, and were the only ideas I could come up with that felt general purpose enough to include by default. Even then, I expect all of these baked in animations are only going to be useful in very specific situations, so I'm choosing to think of them much more like example animations than a strongly recommended universal animation system or something.
The nature of animations is that they tend to be very specific to a given design, so I think it is inevitable that people will be adding their own to support the specific designs they are working on. Adding animations as a feature to Tailwind at least gives them an idiomatic approach for introducing animations, and makes their custom animations feel like they "belong" in the system better than if they were to just throw them in their custom CSS file.