我正在尝试使用导航栏,当用户向上滚动时,导航项会被拉起并且徽标会随着用户向下滚动而缩小。
但是目前导航项目在上升之前会下降...当它恢复时它会在不同的位置结束......
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:
答案 0 :(得分:2)
您在菜单栏上遇到冒泡运动的原因是因为您有
.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 ease
和transition: all 1.0s ease;
注意:在Chrome版本46.0.2490.71
中测试