Animação de elemento tipo balançar

by Salustiano Silva

HTML

<img id="snowman" alt="snowman" src="http://i.stack.imgur.com/AmNNj.png">

JavaScript

$.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();