2013-08-26 218 views
0

我有這個動畫,使一些按鈕在屏幕上'拍'。它工作正常可以免除一件事,動畫太「尖銳」而不流暢,我該如何平滑它?JQuery平滑動畫

function myFunction() { 
    setInterval(function() { 
     tstFnc(); 
    }, 1000); 
} 

var flag = true; 

function tstFnc() { 
    var numM = Math.floor((Math.random() * 10) + 1); 
    var stringM = '#mgf_main' + numM + ' img'; 

    $(stringM).animate({ 
     width: '80px', 
     height: '80px' 
    }, 150, function() { 
     $(stringM).animate({ 
      width: '68px', 
      height: '68px' 
     }, 150, function() { 
      // nothing 
     }); 
    }); 
}; 

回答

2

您可以在animate選項中設置easing屬性。

http://easings.net/

+0

如果你讀會看到的[jQuery的緩解插件]的介紹和鏈接(http://gsgd.co.uk/sandbox/jquery/easing/) – Bart

0

試試這個這裏,animatethis是一個功能和目標元素是元素的ID和速度取決於你..和marginleft是一個例子,你應該嘗試你的代碼。

function animatethis(targetElement, speed) { 
    $(targetElement).animate({ width: "+=10px", height: "+=10px"}, 
      { 
       duration: speed, 
       complete: function() { 
        targetElement.animate({width: "+=10px", height: "+=10px" }, 
        { 
         duration: speed, 
         complete: function() { 
          animatethis(targetElement, speed); 
         } 
        }); 
       } 
      }); 
}