html { background: #4F4F4F; }
.path {
content: "";
width: 20px;
height: 20px;
position: absolute;
background: rgba(149, 147, 241, 0.5);
border-radius: 40px;
top: 28px;
left: 78px;
}
.hand-icon {
position: relative;
background-image: url('https://i.postimg.cc/8556gm60/hand.png');
background-repeat: no-repeat;
background-position: center;
width: 100px;
height: 100px;
animation: spin 2s infinite;
transform-origin: 52% 62%;
}
@keyframes spin {
0% { transform: rotate(30deg); margin-left: 20px; }
50% { transform: rotate(-15deg); margin-left: -20px; }
100% { transform: rotate(0deg); margin-left: 20px; }
}
<div class="swipe">
<div class="path"></div>
<div class="hand-icon"></div>
</div>
I have a good background in CSS, but I am quite new to CSS @keyframes, even though I cannot achieve what is in the screenshot above. The request is to make it animate infinitely and showing that you can drag the screen from the right to left. What I achieved you can see in the code attached.
How can I combine 2 animations and make the purple path animated as well on hand swipe?
Also why the first step is not animated? it is like jumping to 30deg, then it goes smooth. Tried to remake it with 100% { transform: rotate(0deg); margin-left: 20px; }
but id did not work. Can someone point me in the right direction?
Mostly I would like to go with first animation from this example
2
Answers
You could just get the blueish dot to also have an animation which expands the width but keeps the right hand side in the same place.
This snippet assumes you don’t want to change the HTML (e.g. put both in a container) so it does not use right: 0 to fix the right hand side.
This solution achieves exactly what you want:
And yes you need a bit of JS since we’re waiting for an image to arrive to the browser before starting both animations
Regards