I want a rotating animation to be applied to an element: the rotation should start slowly, and then become faster and faster, then it will reach the point from which it will continue very quickly, and then very slowly go slower and slower until it stops.
The graph will look like this:
^ Speed | ******** | ** *** | * **** | * *** | * *** +*-------------------------***-> Time
How can I apply this path to jQuery animate function?
I currently have this:
function spin() { var $myElm = $(".myClass"); function rotate(degrees) { $myElm.css({ '-webkit-transform': 'rotate(' + degrees + 'deg)', '-moz-transform': 'rotate(' + degrees + 'deg)', '-ms-transform': 'rotate(' + degrees + 'deg)', 'transform': 'rotate(' + degrees + 'deg)' }); } $({ deg: 0 }).animate({ deg: 360 * 40 }, { duration: 7000, step: function() { var deg = this.deg; rotate(deg); } }); } spin();
.myClass { position: fixed; top: 30px; left: 30px; height: 200px; width: 200px; background: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="myClass"></div>
This works, but should have a smoother slowdown. How can i do this?
source share