I need to create a animation with the fallowing steps:
- Initial:
elementA
with opacity 0; - Once hover
elementA
‘s container (let’s call itcontainerA
):elementA
translate from (-5px, 5px) to (0px, 0px);elementA
change opacity from0
to1
;- animation duration: 0.5s;
- Once mouse leave
containerA
:elementA
change opacity from1
to0
;elementA
doesn’t change translate position;- animation duration: 0.5s;
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?
2
Answers
Use a
transition
for theopacity
and ananimation
for thetransform
when the container is hovered.Consider different transitions