2013-08-26 57 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); 
         } 
        }); 
       } 
      }); 
}