[英]Multiple Actions div moves up
I would like to create following things with the animation. 我想用动画创建以下内容。 There is a problem which I cannot fix.
有一个我无法解决的问题。
When I click on the red div, it goes down which is fine. 当我单击红色div时,它会下降,这很好。 But when I scroll and click the yellow div the navigation moves up and is away.
但是,当我滚动并单击黄色div时,导航会向上移动并消失。 Is .removeAttr('style') maybe a solution?
是.removeAttr('style')可能的解决方案?
I build a function for that so when I scroll the navigation shifts up. 我为此建立了一个函数,所以当我滚动时,导航会向上移动。
How is it possible that when i drop down the div with click on the red div then scroll down and then click on the yellow div and the navigation DONT moves up and away. 当我通过单击红色div下拉div然后向下滚动,然后单击黄色div时,导航DONT会上下移动,怎么可能。
Here is my Fiddle: Fiddle 这是我的小提琴: 小提琴
/* 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;
});
The problem is this: 问题是这样的:
$(".ab").click(function () {
anim10();
});
change it to 更改为
$(".ab").click(function () {
if ($(window).scrollTop() == 0) {
anim10();
}
});
so it checks if the user is at the top of the page before it closes when you click the yellow div. 因此,当您单击黄色div时,它会在关闭用户之前检查用户是否位于页面顶部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.