在滚动到该元素时,一旦添加了固定的类,侧边栏中的导航就会更改宽度。根据屏幕宽度的不同,它会发生很大的变化。
<div class="col-sm-4 nav_cnt">
<ul class="nav">
<li><a href="destinations2.php">Overview </a></li>
<li><a class="current"href="fac.php">Festiva Adventure Club <i class="fa fa-arrow-circle-right" aria-hidden="true"></i></a></li>
<li><a href="#">Festiva Weeks</a></li>
<li><a href="#">Festiva Exchange Partners</a></li>
<li><a href="#">Voyages by RTX</a></li>
<li><a href="#">Festiva Sailing Vacations</a></li>
</ul>
</div>
@media handheld, only screen and (min-width: 767px) {
.nav_cnt{
position: relative;
}
.fixed{
margin-bottom: 50px;
position:fixed;
top:50px;
width: inherit;
width: 25%;
}
}
$(window).bind('scroll', function() {
if($(window).scrollTop() >= $('.nav_cnt').offset().top - 50 ) {
$('.nav_cnt').find('.nav').addClass('fixed');
}else{
$('.nav_cnt').find('.nav').removeClass('fixed');
}
});https://stackoverflow.com/questions/38227794
复制相似问题