9
The concept being sought is the continuous motion on the X axis between a value and its negative representation:
So far, this concept has a flaw, the animation is performed from 0 degrees to the given value, but then when going back to the same value in negative, there is a jump to 0 degrees and only then animates to the given value. The same happens when returning to the positive value:
See example in Jsfiddle
$.fn.animateRotate = function(angle, duration, easing, complete) {
var args = $.speed(duration, easing, complete);
var step = args.step;
return this.each(function(i, e) {
args.complete = $.proxy(args.complete, e);
args.step = function(now) {
$.style(e, 'transform', 'rotate(' + now + 'deg)');
if (step) return step.apply(e, arguments);
};
$({deg: 0}).animate({deg: angle}, args);
});
};
// animate snowman
var d = 5;
function jingle() {
$("#snowman").animateRotate(d, {
duration: 1337,
easing: 'linear',
complete: function () {
jingle(d = -d);
}
});
}
jingle();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img id="snowman" alt="snowman" src="http://i.stack.imgur.com/AmNNj.png">
The object to animate
The image below is the object you want to animate as you can analyze in the demonstrations.
Question
How can I smooth the effect to get to the desired animation curve?
They built this half-crooked dummy. It leans more to the left... :p
– bfavaretto
@bfavaretto know that the observation has a playful tone (based on true facts :P ), but you can use different angles on each side (for example, -5 and 15 instead of -10 and 10). Obviously in a case like this the right thing to do is to unravel the dummy, but I think that the crooked one contributes to the dramatization of the infinite instability :)
– Bacco