I would like the component content (background and text) to fade in from the left using opacity or other effects. I want it to begin from the left and fade in to full opacity ending on the right. However opacity alone changes the whole component background at the same time. How can i get it to start on the left and finish on the right? I am making a React app and want the effect to happen on rerenders.
I have tied to use translateY(10px) but that moves the whole component and I want the border to stay in place.
.box{
border: 3px solid #fff0f179;
border-radius: 3px;
font-size: 24px;
font-weight: bold;
line-height: 34px;
height: 44px;
margin-right: -1px;
margin-top: -1px;
padding: 0;
text-align: center;
width: 44px;
margin: 3px;
font: 800 24px ;
-webkit-text-fill-color: white;
-webkit-text-stroke: 1px;
animation: fadeBackground 5s ease;
}
@keyframes fadeBackground {
/* 0% {opacity:0%}
40% {opacity:40%}
60% {opacity:60%;}
100% {opacity:100%;} */
0%{
opacity: 0;
transform: translateY(10px);
background-color: white;
}
100%{
opacity: 1;
transform: translateY(0);
}
}
How could I achieve this effect?
2
Answers
.html
.css
And if you want the animation to be executed everytime the div enters the viewport then use
framerMotion
orgetBoundingClientRect()
You can get a fading in effect by covering the element and gradually moving the cover to the right with it having a linear-gradient background with opacity going from 0 to 1.
As this is just to be a visual effect no extra element is added to the DOM. Instead the after pseudo element is used in this snippet: