jquery animate a rotating div

后端 未结 5 966
半阙折子戏
半阙折子戏 2020-12-10 19:21

I would like to rotate a div in an animate function such as

 $(\'div\').animate({rotate: \'30deg\'},1000);

I have found this:

http

5条回答
  •  时光说笑
    2020-12-10 19:45

    Here's the code I used to animate scale and rotation using jQuery:

        var $elem = $('#myImage');
        $({ deg: 0 }).animate({ deg: 359 }, {
            duration: 600,
            step: function (now) {
                var scale = (2 * now / 359);
                $elem.css({
                    transform: 'rotate(' + now + 'deg) scale(' + scale + ')'
                });
            }
        });
    

    This basically loops from 0 to 359, rotates my image by that many degrees, and also scales between 0 and 2, so the image grows from nothing to double size during the animation.

提交回复
热议问题