I have an animation going in css that is supposed to make it seem like the div is "floating" or "hovering", slowly moving. But it just doesn’t seem natural at all, it slows by the corners. What detail may make it seems smoother?
Snippet
@keyframes floating {
0% {
transform: translate(0, 0);
}
25% {
transform: translate(10px, 0);
}
50% {
transform: translate(10px, 10px);
}
75% {
transform: translate(0, 10px);
}
100% {
transform: translate(0, 0);
}
}
.floating-div {
animation: floating 8s infinite;
}
<div class="floating-div" style="width:100px; height: 100px; border: 2px solid #000000; border-radius: 10px;">
Bzbz
</div>
3
Answers
You can use animation timing function with linear value, so that animation doesn’t slow down on the corners and stay uniform. Here is the updated code. Try this:-
The animation progress through a duration of each cycle can also be adjusted using cubic-bezier function. For linear progress, the value of cubic-bezier function will be 0.0, 0.0, 1.0, 1.0. Here is the sample code:-
small improvement with gradient 😉
By using animation-timing-function, you can enhance the smoothness of your animation
I recommend to check https://animista.net/play/background/bg-pan/bg-pan-right, there are many ready animations
To make the animation of the div floating or hovering smoother, you can adjust the keyframes in the CSS animation. Currently, the animation moves the div in fixed steps, causing it to slow down at the corners. Here’s an updated version of the CSS animation that should provide a smoother floating effect:
Additionally, you can experiment with the animation-timing-function property to change the easing of the animation. The default value is ease, which can cause the animation to slow down at the beginning and end. You can try using different values such as linear, ease-in, ease-out, or ease-in-out to see which one produces the desired smoothness. For example:
By making these adjustments, you should be able to achieve a smoother and more natural floating or hovering effect for your div.