2012-11-11 30 views
0

我動畫元素的高度:將緩動添加到以下jQuery動畫中?

// Animate height of items 
    $j(".item .row").toggle(function(){ 
    $j(this).animate({height:500},200); 
    },function(){ 
    $j(this).animate({height:300},200); 
    }); 

我想知道如何添加寬鬆呢? (例如動畫放緩接近尾聲?)

回答

3

定義放寬,通過以下方式

$('selector').animate({ 
    prop:1 
},{ 
    easing: easing, //Something like 'linear' 
    duration: duration, 
    complete: callback 
}); 

您可以添加其他的緩解效應也通過包括Easing Plugin

在你的情況下,它會像

$j(".item .row").toggle(function(){ 
    $j(this).animate({height:500}, { 
     easing: 'linear', 
     duration: '200' 
    }); 
    },function(){ 
    $j(this).animate({height:300},{ 
     easing: 'linear', 
     duration: '200' 
    }); 
}); 
+0

對不起,我有點困惑如何在整合與我現有的代碼。你能舉個例子嗎? – alexchenco

+0

@alexchenco,當然我更新了答案。一探究竟。 – Starx

+0

非常感謝。我會嘗試插件。我認爲'線性'和'擺動'並不是我正在尋找的緩解方法。 – alexchenco