私のコードは現在、両方のアニメーションを同時に実行しています。
- スライドダウン
- divをアニメーション化
スライドダウンのようなアニメーションが最初に発生し、完了したら別のアニメーションを実行したいと思います。
注: 最初のslideDown アニメーションは 1 回発生し、残りのアニメーションは繰り返し発生します。つまり、他のタグをクリックします。
ps:コールバックを実行しようとしましたが、最初のslideDownアニメーションを1回実行したいため、残りのコードが機能しなくなります。
適切なデモについては、jsFiddle DEMOを参照してください。
前もって感謝します!
以下の私のコードを見てください。参考までにコメントさせていただきました。
$(function() {
var content = $('#content'),
contentHeight = content.height(),
nav = $('#nav'),
count = 0;
// on load content height is shorter
content.height(100);
nav.find('a').on('click', function() {
var $this = $(this),
parent = $this.parent(),
targetElement = $this.attr('href');
//Does the slide down animation once
if (count === 0) {
content.animate({'height': contentHeight });
count = 1;
}
//only add active class if parent does not have it and then animate it
if ( !parent.hasClass('active') ) {
parent.addClass('active');
//animate in
$(targetElement).animate({
left: '-=200px',
'margin-left': '50%',
opacity: 1
}, 500);
//Gets older clicked element
var oldClickedElement = $('.active').not(parent).removeClass('active').find('a').attr('href');
//only if old click element exists the do the animation
if (oldClickedElement) {
//animate out + reset to start
$(oldClickedElement).animate({
left: 0,
'margin-left': '-50%',
opacity: 0
}, 500, function() {
$(oldClickedElement).css({
'margin-left' : '100%',
left: 0
});
});
}
}
return false;
});
});