gpt4 book ai didi

javascript - CSS 动画在恢复之前下降

转载 作者:可可西里 更新时间:2023-11-01 13:28:05 25 4
gpt4 key购买 nike

我正在尝试创建一个导航栏,其中导航项会在用户滚动时上拉, Logo 会在用户滚动时缩小,而在用户向上滚动时会缩小。

但目前导航元素在上升之前先下降......当它恢复时它最终会在不同的位置......

HTML:

<nav class="navbar">
<a href="#">James Jones</a>
<ul class="nav-items">
<li><a href="#about">About</a></li>
<li><a href="#">Work</a></li>
<li><a href="#">Photography</a></li>
<li><a href="#">Videos</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>

CSS:

.navbar {
background: #fff;
font-family: ShorelinesScriptBold;
font-size: 2em;
font-weight: 900;
height: 150px;
line-height: 100px;
position: fixed;
text-align: center;
-webkit-transition: all 1.0s ease;
transition: all 1.0s ease;
width: 100%;
z-index: 10000;
}

.navbar a {
color: #343434;
display: block;
/*margin: 0 0 -24px 0;*/
margin: 0 0 -55px 0;
text-decoration: none;
}

.navbar a:hover {
color: #343434;
text-decoration: none;
}

.shrink {
font-family: 'Radley', serif;
font-size: 1em;
font-weight: 500;
height: 50px;
letter-spacing: 1px;
line-height: 50px;
position: fixed;
top: -5px;
text-transform: uppercase;
}

.nav-items {
background: #fff;
-webkit-transition: all 1.0s ease;
transition: all 1.0s ease;
}

.nav-items li {
display: inline-block;
font-family: Helvetica;
font-size: 12px;
letter-spacing: 0;
text-transform: uppercase;
}

.nav-items a {
color: gray;
font-weight: 300;
margin: 0 15px;
text-decoration: none;
}

.nav-items a:hover {
color: #FFAED8;
}

.margin {
margin: 30px 0 0 0;
}

Javascript:

$(window).scroll(function() {
if ($(document).scrollTop() > 150) {
$('.navbar').addClass('shrink');
$('.nav-items').addClass('margin');
} else {
$('.navbar').removeClass('shrink');
$('.nav-items').addClass('margin');
}
});

JS fiddle :

https://jsfiddle.net/gkrtk8s3/4/

最佳答案

您在菜单栏上遇到冒泡运动的原因是因为您有

.nav-items {
background: #fff;
-webkit-transition: all 1.0s ease;/* Duplicate Transition. you already have a transition on your nav tag
transition: all 1.0s ease; /* Duplicate Transition. you already have a transition on your nav tag
}

从上面取出两行 -webkit-transition: all 1.0s easetransition: all 1.0s ease;

注意:在 chrome 版本 46.0.2490.71 中测试

关于javascript - CSS 动画在恢复之前下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34458885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com