看到更新後的提琴: http://jsfiddle.net/QfeC2/3/
function AnimateRotate(angle) {
// caching the object for performance reasons
var $elem = $('div');
// we use a pseudo object for the animation
// (starts from `0` to `angle`), you can name it as you want
$({deg: 0}).animate({deg: angle}, {
duration: 2000,
step: function(now) {
// in the step-callback (that is fired each step of the animation),
// you can use the `now` paramter which contains the current
// animation-position (`0` up to `angle`)
$elem.css({
transform: 'rotate(' + now + 'deg)'
});
},
complete: function(){
AnimateRotate(360);
}
});
}
AnimateRotate(360);
UPDATE
旋轉每個週期後回:
http://jsfiddle.net/QfeC2/9/
var boolDirection = true;
function AnimateRotate(angle) {
// caching the object for performance reasons
var $elem = $('div');
// we use a pseudo object for the animation
// (starts from `0` to `angle`), you can name it as you want
$({deg: 0}).animate({deg: angle}, {
duration: 2000,
step: function(now) {
// in the step-callback (that is fired each step of the animation),
// you can use the `now` paramter which contains the current
// animation-position (`0` up to `angle`)
$elem.css({
transform: 'rotate(' + now + 'deg)'
});
},
complete: function(){
if(boolDirection)
{
AnimateRotate(-360);
boolDirection = false;
}
else
{
AnimateRotate(360);
boolDirection=true;
}
}
});
}
AnimateRotate(360);
感謝@Anton,我想不過 – Liam
@Liam你希望它看起來像這一點,平穩地旋轉? http://jsfiddle.net/QfeC2/8/ – Anton
@Liam或者你可以使用純CSS http://jsfiddle.net/QfeC2/10/ – Anton