So far, this concept has a failure, the animation is performed from 0 degrees to the value given, but then when going back to the same negative value, there is a 0 degree jump and only then it animates to or value provided. The same thing happens when you return 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><imgid="snowman" alt="snowman" src="http://i.stack.imgur.com/AmNNj.png">
Theobjecttoanimate
Theimagebelowistheobjectyouwanttoanimateasyoucanparseinthedemonstrations.
Question
How can I smooth the effect so as to reach the desired animation curve?