2013-04-18 149 views
0

我想做一個有趣的函數來旋轉元素360.問題是它只執行第一次,我不知道爲什麼!jQuery上的動畫只執行一次

jQuery.fn.circularFun = function() { 
      this.stop().animate(
       {rotation: 360}, 
       { 
        duration: 500, 
        step: function(now, fx) { 
        $(this).css({"transform": "rotate("+now+"deg)"}); 
        } 
       } 
      ); 
     } 

謝謝!!

+0

你想讓它保持旋轉 –

+0

讓你的函數調用自己遞歸 –

+0

看看他的。 http://stackoverflow.com/questions/6767286/jquery-continuously-loop-animation –

回答

3

第一次旋轉後,它已經旋轉到360。完成後,您需要將其設置爲0

+1

或在開始之前:'this.stop().css('rotation',0).animate(...)' –

+0

@Alexey:當然!原理相同。 –

+0

謝謝!這就是發生了什麼! –