jQuery: how do I animate a div rotation?

后端 未结 8 975
梦毁少年i
梦毁少年i 2020-11-29 05:47

I can rotate a div with css, and jquery .rotate, but i don\'t know how to animate it.

8条回答
  •  遥遥无期
    2020-11-29 06:38

    This works for me:

    function animateRotate (object,fromDeg,toDeg,duration){
        var dummy = $('')
        $(dummy).animate({
            "margin-left":toDeg+"px"
        },{
            duration:duration,
            step: function(now,fx){
                $(object).css('transform','rotate(' + now + 'deg)');
            }
        });
    };
    

提交回复
热议问题