I want to have a spinning animation applied to an element: the rotation should start slowly and then become faster and faster, then it will reach a point from where it will continue to be very fast and then very slowly go slower and slower until it will stop.
The graph would look like this:
^ Speed
| ********
| ** ***
| * ****
| * ***
| * ***
+*-------------------------***-> Time
How can I apply this path to the jQuery animate
function?
Currently I 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 it should have a smoother slowing down. How can I do that?
Ease-in-out can be used in css transitions and animations , not in transforms. You should use transitions for that desired effect with ease-in-out in transition-timing-function
You can add in your desired element class and then make an another class like .effect and write css for it in .css file
and then in your .js file , write under the action or event call function
Its jquery with some css in your stylesheet
Try using jQuery Easing
easeInOutQuart
function ; ifthis.deg
:now
parameter ofstep
function is less than6000
or greater than8000
, set variabledeg
tonow
divided by8
, which is an even divisor of14400
:360 * 40
You can try using
ease-in-out
in css transitions. If you want to define a more specific animation, you can try to define your own by using a tool like this one: ceaserFor example:
Edit: If you want to only use the animate function of jQuery for this, you can try to use the jQuery easing plugin
See the available easing animation in this cheat sheet : http://easings.net/
@ Ionică Bizău you can control animation timing by writing
or if you are using a transition then