0
我已經編寫了此功能來爲卡片樣式佈局創建「顯示更多」功能。我最初編寫它的時候都是在一個點擊函數中,但是隨後範圍發生了變化,我需要將這些命令移動到它們自己的函數中,現在動畫非常直觀,可以更多地忽略。我有一種感覺,它在動畫和引起衝突時與變量更新有關,但我不確定如何繞過該變量,或者在採用一個高度後將該變量設置爲常量。如何優化此功能以更平滑地進行動畫製作
//This function removes the reveal more trigger and slides "new-deals" down to auto height
function revealMore() {
var containerHt = $("#new-deals").children().height; //set animation height for "reveal more" function
//Reveal More function which handles animating container height to that of contained elements and removes the reveal more trigger element
if (($("#new-deals").height) >= containerHt) {
$("#new-deals").animate({height: containerHt}, 400, function() {
$("#new-deals").css({height: 'auto'});
});
$("#new-deals").siblings('.reveal-more').remove();
}
}
$(".reveal-more a").click(function() {
revealMore();
return false;
});
您可以從創建http://jsfiddle.net開始重現您的問題 – Itay
獲得真正流暢動畫的唯一方法是使用CSS'translate3d'屬性,因爲它是硬件加速的。 – Mathletics