How to get a gravity effect in a CSS animation?
css, physics
Solution
I think that you can do it using bezier curves.
in you case, it could be something like that:
-webkit-transition: all 500ms cubic-bezier(0.310, 0.440, 0.445, 1.650);
-moz-transition: all 500ms cubic-bezier(0.310, 0.440, 0.445, 1.650);
-ms-transition: all 500ms cubic-bezier(0.310, 0.440, 0.445, 1.650);
-o-transition: all 500ms cubic-bezier(0.310, 0.440, 0.445, 1.650);
transition: all 500ms cubic-bezier(0.310, 0.440, 0.445, 1.650); /* custom */
-webkit-transition-timing-function: cubic-bezier(0.310, 0.440, 0.445, 1.650);
-moz-transition-timing-function: cubic-bezier(0.310, 0.440, 0.445, 1.650);
-ms-transition-timing-function: cubic-bezier(0.310, 0.440, 0.445, 1.650);
-o-transition-timing-function: cubic-bezier(0.310, 0.440, 0.445, 1.650);
transition-timing-function: cubic-bezier(0.310, 0.440, 0.445, 1.650); /* custom */
I haven't done it by myself, check this link:
css easing animation tool
I have made an example in a JSFiddle.
I put an outer div to make the hover stable:
<div class="container">
<div class="moving"></div>
</div>
and the CSS is as follows:
.moving {
position: absolute; width: 200px; height: 150px; top: 50px; left: 50px;
background-color: green;
-webkit-transition: all 5s cubic-bezier(0.310, 0.440, 0.445, 1.650);
}
.container:hover .moving {
zoom: 1.5;
}
Editing
Just an image of what can you get with a bezier curve (from the ease animation tool page) to show that the object speed doesn't need to be constant (and can be almost parabolic)
Problem
I want to animate an element as if you're looking down at the Earth. The element jumps towards you, hits its apex, and falls back down a little. A side view of the trajectory would be like this: ``` _ / \ / | | | ``` I wasn't able to attain a realistic effect with keyframe animations. Mine looks artificial like this: ``` /\ / \ / / / ``` CSS ``` @keyframes springIn { 0% { transform: scale(0.0); } 80% { transform: scale(1.2); } 100% { transform: scale(1.0); } } .someElement { animation: springIn 1s linear 1s 1 forwards; } ``` How do you put parabolic function on the animation to get the gravity effect? I thought I could use Bezier Curves, but the CSS standard does not allow points outside of [0, 0].