I need to create a animation with the fallowing steps:
elementA with opacity 0;elementA's container (let's call it containerA):
elementA translate from (-5px, 5px) to (0px, 0px);elementA change opacity from 0 to 1;containerA:
elementA change opacity from 1 to 0;elementA doesn't change translate position;I've achieved this effect by adding/removing CSS class, you can see the here (https://jsbin.com/buqexadiru/edit?html,css,js,console,output)
My question is, how can I achieve this effect with pure CSS, without the add/remove class step; Is this possible?
Use a transition for the opacity and an animation for the transform when the container is hovered.
.container {
margin: 1em;
border: 2px solid blue;
background: lightblue;
width: 50vh;
aspect-ratio: 1;
}
.item {
width: 20vh;
aspect-ratio: 1;
background: green;
opacity: 0;
transform: translate(0%, 0%);
transition: opacity .5s;
}
.container:hover .item {
opacity: 1;
animation-name: appear;
animation-duration: .5s;
animation-fill-mode: forwards;
}
@keyframes appear {
0% {
transform: translate(-50%, -50%);
}
100% {
transform: translate(0%, 0%);
}
}
<div class="container">
<div class="item"></div>
</div>