I guess this would apply to swinging, or bouncing. An example on how to make an object swing here in another post, where this code was posted: http://jsfiddle.net/gVCWE/149/
How would you make the swinging slow down to a stop?
.box{
width:50px; height:50px;
background: yellow;
border: 1px solid black;
margin:100px;
position: relative;
float: left;
-moz-animation: 3s ease 0s normal none infinite swing;
-moz-transform-origin: center top;
-webkit-animation:swing 3s infinite ease-in-out;
-webkit-transform-origin:top;
}
@-moz-keyframes swing{
0%{-moz-transform:rotate(-3deg)}
50%{-moz-transform:rotate(3deg)}
100%{-moz-transform:rotate(-3deg)}
}
@-webkit-keyframes swing{
0%{-webkit-transform:rotate(-3deg)}
50%{-webkit-transform:rotate(3deg)}
100%{-webkit-transform:rotate(-3deg)}
}
I would like to do other ‘inertia effects’ as well. I do not mind using JavaScript or JQuery if that’s necessary. I feel like CSS alone or keyframes is not enough for what I want to do.
I’m fine using setInterval and doing something like this:
function prepareAnimation()
{
setInterval(slowAnimation, 200)
}
function slowAnimation()
{
speed=$(".box").getSpeed(); // how would I write getSpeed?
if(speed<=0) return;
speed = speed - .1;
$(".box").setSpeed(speed); // how would I write setSpeed (degree would be set in here too)?
}
I do not know the best way to changing animation properties through script. Especially when it comes to changing the duration in the middle of an animation, which I’m not sure is possible at all. Thanks.
http://jsfiddle.net/gVCWE/150/
CSS
You can switch the initial direction by making the initial values of
anganddirnegative. You can make the “swinging” slow more quickly by increasing the value ofdAng, but it should be a factor ofang.