基本上我有一个带有相同页面锚点的固定导航栏,我想在点击链接并将其带到页面的该部分后保持链接处于活动状态。如果链接到另一个页面,这很简单,但我无法弄清楚如何在这里。
这就是我所拥有的。我将向您展示第一个链接和部分,因为解决方案很可能与以下链接相同。我没有写过任何CSS,因为我不知道如何解决这个问题。
<nav id="navbar" class="navbar">
<div id="navContent" class="areaMargin navContent row">
<a href="#schedWrapper" class="link btn btn-lg btn-primary col-lg-2 col-md-2 col-sm-2 col-xs-12">Scheduling</a>
</div>
</nav>
<section id="schedWrapper" class="bgWrapper ">
<img class="bgImg" src="images/bg/scheduling-bg.jpg">
<article id="schedContent" class="areaMargin fittext">
<header class="top">
<div class="col1"><h1>A New Way<br />To Schedule<br />Everything</h1></div>
<div class="col2"><img src="images/scheduling-client-group-event.png"></div>
</header>
<div class="clearfix"></div>
<div id="schedBottom">
<p>One calendar that lets you manage schedules for your team<br />
and your spots, all in one calendar, with options of sharing your<br />
own personal schedule, and you can accept and decline<br />
appointments with any device.</p>
</div>
</article>
答案 0 :(得分:0)
使用jQuery,您只需在链接上切换active
类:
$('#navContent a').click(function(){
/* remove class from prior active link*/
$('.activeLinkClass').removeClass('activeLinkClass');
/* "this" is current link clicked*/
$(this).addClass('activeLinkClass');
});