这是我开始工作的可重用版本。希望它可以帮助你。
$(function () {
var rotateAnimation = function (props) {
// init animation props
var rotateEl = props.el,
curAngle = props.startAngle,
endAngle = props.endAngle;
// scope angle to parent function
var angleValue = 'rotate(' + curAngle + 'deg)';
// define worker function
var rotate = function () {
// increment the angle
curAngle += props.increment;
// see if we are done animating
if (curAngle >= endAngle) {
curAngle = endAngle;
clearInterval(timer);//stop looping
}
// create css value
angleValue = 'rotate(' + curAngle + 'deg)';
rotateEl.css({
'-moz-transform': angleValue,
'-webkit-transform': angleValue,
'-o-transform': angleValue,
'-ms-transform':angleValue
});
};
var timer = setInterval(rotate, props.delay);//let the fun begin
};
$('#super').on('click', function () {
rotateAnimation({
el: $(this),
startAngle: 0,
endAngle: 1234,
delay: 1,
increment: 3
});
});
});