アニメーションを互いに積み重ね、デフォルトのアニメーション キューイングを無効にします。
$(".thebox")
.animate({height: "toggle"}, {duration: 250, queue:false})
.animate({opacity: "toggle"}, {duration: 500, queue:false}); // Runs twice as slow.
編集:
トグルを使用してイベントが 2 回トリガーされるため、ボックスを非表示にするか表示するかを検出するために、別のアプローチが必要です。簡単な解決策の 1 つは、次のようなヘルパー クラスです。
var theBox = $('.thebox');
if (theBox.hasClass('active')) {
// It is active, then fade it out
thebox
.removeClass('active')
.animate({height: 0}, {duration: 250, queue:false})
.animate({opacity: 0}, {duration: 500, queue:false});
} else {
// It is not active, show it
thebox
.addClass('active')
.animate({height: 'auto'}, {duration: 250, queue:false})
.animate({opacity: 1}, {duration: 500, queue:false});
}
注目すべき点: animate() の代わりに、slideUp、slideDown、fadeIn、fadeOut を使用してアニメーションを実行できます。また、上記は class を持つ要素が 1 つしかないことを前提としていることにも注意してくださいtheBox
。