2012-08-24 150 views
0

我已经定义了一个函数来为顶部的7个div动画。我试图用stop(true,false)函数来停止所有的元素。并通过再次调用该函数重新启动动画。请参阅下面的代码。问题是在我调用重新启动动画的函数后,动画变得非常慢。它会减速几秒钟,然后再次变为正常速度。有谁知道原因。请帮忙!!!由于jQuery动画在呼叫停止并重新启动后减速

我的代码是在下方附上

autoAnimate(5000); 
$('#scroller_container').mouseenter(function(){ 
    $('#scroller .galleryThumb').stop(true, false); 
}); 
$('#scroller_container').mouseleave(function(){ 
    autoAnimate(5000); 
}); 

function autoAnimate(speed) { 
    $('#scroller .galleryThumb:eq(0)') 
     .animate({'top':'-122px'},speed,'linear',function(){ 
      if(!autoFlag) { 
      index  = $('#scroller .galleryThumb:last').attr('id'); 
      index  = index.substr(5, index.length); 
      index  = parseInt(index); 
      index  = index + 1; 
      autoFlag = true; 
      } 
      if(index == numberOfAds) { index = 0; } 

      $('#scroller .galleryThumb:eq(0)').remove(); 
      $('#scroller').append(adUnitContainer[index]); 
      $('#scroller .galleryThumb:eq(6)').css('top','732px'); 
      index++; 
      autoAnimate(speed); 
    }); 
    $('#scroller .galleryThumb:eq(1)').animate({'top':'0px'},speed,'linear'); 
    $('#scroller .galleryThumb:eq(2)').animate({'top':'122px'},speed,'linear'); 
    $('#scroller .galleryThumb:eq(3)').animate({'top':'244px'},speed,'linear'); 
    $('#scroller .galleryThumb:eq(4)').animate({'top':'366px'},speed,'linear'); 
    $('#scroller .galleryThumb:eq(5)').animate({'top':'488px'},speed,'linear'); 
    $('#scroller .galleryThumb:eq(6)').animate({'top':'610px'},speed,'linear'); 
} 
+0

它可能有助于在jsfiddle.net重新创建它,并在此处链接到它,以便其他人可以看到您的问题正在实施。 – JasCav

回答

0

如果你有一个5秒钟的动画,你停止在中间,然后重新启动具有相同的最终点相同的动画为动画,你告诉它运行5秒钟,它会变慢,因为它在5秒内的距离较短。

如果您希望以之前相同的速度重新启动,则必须缩短第二个动画中的时间以反映按比例分配的时间量。

还记得speed = distance/time。如果重新开始动画的距离较短,但同一时间,则速度会变慢,除非您也按比例缩短时间。

+0

谢谢,那真的是我需要的。 – eded