I was trying to build a short bounce animation, which bounces a small error message on screen when a user fails to log in. This message only needs to bounce a few seconds to get the user's attention, without annoying the user. As you can see from the link in @Matt's answer, tailwind uses the following css code for the bounce class:
animation: bounce 1s infinite;
Where bounce
refers to the @keyframes
configuration, 1s
refers to the duration of a single iteration and infinite
refers to the total number of iterations, going on forever in this case. This means we somehow have to adjust that last part.
The neat thing about tailwind is that you can extend the configuration in tailwind.config.js
and make your own classes. Here, I am borrowing the keyframes from the existing bounce class to make my own shorter version out of it:
// tailwind.config.js
module.exports = {
theme: {
extend: {
animation: {
// Bounces 5 times 1s equals 5 seconds
'bounce-short': 'bounce 1s ease-in-out 5'
}
}
}
}
Easy as that, without polluting other files with custom css code. If needed you can even extend the configuration with custom keyframes, meaning that you have total control of the intermediate steps of the animation. The official documentation demonstrates how to achieve this.