减慢动画jquery?

时间:2012-08-06 18:12:02

标签: jquery

基本上,我有一个工作功能,我想稍微调整一下,但我无法弄明白。这会在按下后切换div的动画,虽然不是仅仅“停止”或清除定时器,我希望它慢慢旋转回0然后清除定时器......这可能吗?

var $elem = $('#optionBtn'),
    degree = 0,
    timer;

function rotate() {
    $elem.css({
        WebkitTransform: 'rotate(' + degree + 'deg)'
    });
    $elem.css({
        '-moz-transform': 'rotate(' + degree + 'deg)'
    });
    timer = setTimeout(function() {
        ++degree;
        rotate();
    }, 5);
}
$("#optionBtn").toggle(

function(e) {
    rotate();
},

function() {
    clearTimeout(timer);
});

三江源!

1 个答案:

答案 0 :(得分:0)

请尝试使用此jQuery路径。它会简化你的代码:

http://www.zachstronaut.com/posts/2009/08/07/jquery-animate-css-rotate-scale.html