I was working with tailwind animation and I needed to create a custom animation in tailwind. The issue is that when I try to pass the value for the animation-delay using a variable or array, the animation does not seems to work. It does seems to work just fine when I explicitly gives the animation delay value.
If you are thinking that the variable value is not being passed correctly I assure you that it is passing correctly I have even checked in the chrome dev tools that the animation class is being applied.
And the most weird thing happening is that when I pass delay value 0.1,0.2 or 0.3 from the variable it works just fine. But if I try using any other value lets say 0.4,0.24,etc it will not work.
This is a really strange and weird issue I am having and had spent over a day on it but still nothing.
Keep in mind Its not the main issue the issue is very vast and I try to sum up the issue in a very simple example so restrain yourself from giving other possible solution. I do have other solution but I need this to work to make my animations dynamic.
Here is the Code that will not work as i am passing delay value 0.4
function AnimationBox() {
const delay = 0.4;
return (
<div
className={`flex h-80 w-full animate-[slideIn_0.5s_${delay}s_both] bg-white`}
></div>
);
}
export default AnimationBox;
Here is the Code that will work as i am passing delay value 0.2 (because values like 0.1, 0.2 and 0.3 works just fine)
function AnimationBox() {
const delay = 0.2;
return (
<div
className={`flex h-80 w-full animate-[slideIn_0.5s_${delay}s_both] bg-white`}
></div>
);
}
export default AnimationBox;
Here is the Code that will also work as i am giving delay value explicitly and no matter the value it will work just fine.
function AnimationBox() {
return (
<div
className={`flex h-80 w-full animate-[slideIn_0.5s_0.123s_both] bg-white`}
></div>
);
}
export default AnimationBox;
I just need a reason why its not working and to understand what is thing behaviour.
As per the documentation:
Some values work (like
0.1,0.2) because you have some complete class names else where likeanimate-[slideIn_0.5s_0.1s_both]that don't use string interpolation and are written as-is. The usage with the string interpolation then "piggy-backs" off this, and thus purely coincidental that it works for these values.To make it work, you could:
styleattribute:safelistthe classes, if you have a limited number of known values: