gpt4 book ai didi

javascript - 导航栏过渡动画仅在向上滚动时

转载 作者:行者123 更新时间:2023-11-27 23:04:06 25 4
gpt4 key购买 nike

目前,我的导航栏有一个很好的过渡,当你向上滚动时它会淡入。我遇到的问题是,当我向下滚动时,过渡动画不适用,并且没有淡入淡出就消失了。

这是转换的代码:

transition: transform 500ms ease, background 500ms ease;
-webkit-transition: transform 500ms ease, background 500ms ease;

应用转换的类是 .main-menu,但是它只在向上滚动时触发,而不会在向下滚动时触发。我不确定为什么会发生这种情况,因为 .main-menu 始终存在,所以无论菜单栏是否显示,它都不应该触发吗?

这是页面的链接:http://eg-graphics.com/Website%20New/about-us.html

最佳答案

感谢@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);
}

关于javascript - 导航栏过渡动画仅在向上滚动时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58829259/

25 4 0