多个动作div向上移动

我想用动画创建以下内容。 有一个我无法解决的问题。

当我点击红色div时,它会下降,这很好。 但是当我滚动并单击黄色div时,导航向上移动并离开。 .removeAttr(’style’)可能是一个解决方案吗?

我为此构建了一个函数,所以当我滚动导航向上移动时。

怎么可能当我通过点击红色div下拉div然后向下滚动然后点击黄色div并且导航DONT向上移动并离开。

这是我的小提琴: 小提琴

/* MAIN FUNCTION */ var $a = $(".a"), $b = $(".b"), $c = $(".c"); function anim1() { $b.animate({width: 395}, {duration: 300, complete: anim2}); } function anim2() { $a.animate({top:"0px"}, {duration: 400}); $c.animate({top:"0px"}, {duration: 400}); } $(".b").click(function() { anim1(); }); function anim10() { $c.animate({top:"-50px"}, {duration: 200}); $a.animate({top:"-50px"}, {duration: 200 , complete: anim20}); } function anim20() { $b.animate({width: 137}, {duration: 200}); } $(".ab").click(function() { anim10().removeAttr('style'); }); /* SLIDE UP ONLY MAIN NAVIGATION */ $(window).scroll(function() { if ($(this).scrollTop() < 200) { $(".example").animate({top:"0px"},{duration: 50,easing: 'easeInOutCubic'}); } else { $(".example").animate({top:"-50px"},{duration: 50,easing: 'easeInOutCubic'}); } return false; }); 

问题是这样的:

 $(".ab").click(function () { anim10(); }); 

改为

 $(".ab").click(function () { if ($(window).scrollTop() == 0) { anim10(); } }); 

因此,当您单击黄色div时,它会在关闭之前检查用户是否位于页面顶部

演示