我在列表中设置了固定导航,如下所示,但它在CSS中旋转到侧边菜单。
<ul class="desktop-nav">
<li>
<a href="#section4" class="scroll">Section 4</a>
</li>
<li>
<a href="#section3" class="scroll">Section 3</a>
</li>
<li>
<a href="#section2" class="scroll">Section 2</a>
</li>
<li class="current">
<a href="#section1" class="scroll">Section 1</a>
</li>
</ul>
我基本上需要我的jQuery从列表底部(从之前的li中删除它)来反转'.current'类在滚动时而不是从上到下它当前是:
$(window).scroll(function() {
var windowTop = $(window).scrollTop() + $('.desktop-nav').outerHeight(true);
$('.desktop-nav li').not('.lastNav').each(function() {
var href = $('a', this).attr('href');
if(href == '#header-hold') href = 'body';
var elementTop = $(href).offset().top - 0;
if(windowTop >= (elementTop)){
$('.desktop-nav li').removeClass('current');
$('a[href^="'+href+'"]').parent().addClass('current');
if(href == 'body') { $('.desktop-nav li:eq(0)').addClass('current'); }
}
});
});
任何帮助将不胜感激!