Issue
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?
Solution
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>
Answered By - Paulie_D
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.