导航栏过渡动画仅在向上滚动时
Navbar transition animation only on scroll up
目前,我的导航栏有一个很好的过渡,当您向上滚动时它会淡入。
我遇到的问题是,当我向下滚动时,过渡动画不适用,并且没有淡入淡出就消失了。
这是转换代码:
transition: transform 500ms ease, background 500ms ease;
-webkit-transition: transform 500ms ease, background 500ms ease;
应用过渡的 class 是 .main-menu
,但它仅在向上滚动时触发,而不会在向下滚动时触发。我不确定为什么会发生这种情况,因为 .main-menu
始终存在,所以无论菜单栏是否显示,它都不应该触发吗?
感谢@MuraliNepalli 的评论指导。多亏了这一点,我才能够解决这个问题。答案如下:
在 CSS 我需要设置以下
.header_area {
position: fixed; /* position needed to be fixed */
width: 100%;
top: -120px; /* top needed to be -120px */
left: 0;
z-index: 99;
}
.header_area.navbar_fixed .main_menu {
position: fixed;
width: 100%;
top: -120px; /* top needed to be -120px */
left: 0;
right: 0;
background: #000;
transform: translateY(120px); /* translation needed to be -120px */
box-shadow: 0px 3px 16px 0px rgba(0, 0, 0, 0.1);
}
目前,我的导航栏有一个很好的过渡,当您向上滚动时它会淡入。 我遇到的问题是,当我向下滚动时,过渡动画不适用,并且没有淡入淡出就消失了。
这是转换代码:
transition: transform 500ms ease, background 500ms ease;
-webkit-transition: transform 500ms ease, background 500ms ease;
应用过渡的 class 是 .main-menu
,但它仅在向上滚动时触发,而不会在向下滚动时触发。我不确定为什么会发生这种情况,因为 .main-menu
始终存在,所以无论菜单栏是否显示,它都不应该触发吗?
感谢@MuraliNepalli 的评论指导。多亏了这一点,我才能够解决这个问题。答案如下:
在 CSS 我需要设置以下
.header_area {
position: fixed; /* position needed to be fixed */
width: 100%;
top: -120px; /* top needed to be -120px */
left: 0;
z-index: 99;
}
.header_area.navbar_fixed .main_menu {
position: fixed;
width: 100%;
top: -120px; /* top needed to be -120px */
left: 0;
right: 0;
background: #000;
transform: translateY(120px); /* translation needed to be -120px */
box-shadow: 0px 3px 16px 0px rgba(0, 0, 0, 0.1);
}