本文介绍了jQuery Animate transform infinite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置无限旋转,但它不工作。

I need to set infinite rotating but it doesn't work.

function AnimateRotate(angle) {
    var $elem = $('.icon-repeat');

    $({deg: 0}).animate({deg: angle}, {
        duration: 5000,
        step: function(now) {
            $elem.css({
                transform: 'rotate(' + now + 'deg) infinite'
            });
        }
    });
}

这是我的代码,此行 transform: '+ now +'deg)infinite' ..
如果我移除无限它适用于一个旋转,但我需要旋转无限..
要写入JS,我想...

That is my code, and this line transform: 'rotate(' + now + 'deg) infinite' ..if I remove infinite it works for one rotate, but I need to rotate infinite..I have to write it in JS, I think...

推荐答案

尝试这个,你应该设置重复的值。 AnimateRotate(degree,repeatcount)。

Try this, You should set the "repeat" value. AnimateRotate(degree, repeatcount).

在您的情况下,将重复计数设为无限 。 >

In your case set the repeatcount as "infinite".

function AnimateRotate(angle,repeat) {
    var duration= 1000;
    setTimeout(function() {
        if(repeat && repeat == "infinite") {
            AnimateRotate(angle,repeat);
        } else if ( repeat && repeat > 1) {
            AnimateRotate(angle, repeat-1);
        }
    },duration)    
    var $elem = $('.icon-repeat');

    $({deg: 0}).animate({deg: angle}, {
        duration: duration,
        step: function(now) {
            $elem.css({
                'transform': 'rotate('+ now +'deg)'
            });
        }
    });
}
AnimateRotate(45,"infinite");

这篇关于jQuery Animate transform infinite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:05