我只有一个页面。我的页面上至少有四个部分。active当滚动到相应部分的底部时,我必须将类添加到菜单上的 li 标记中。例如,如果屏幕上有关于我们的部分,则将活动类添加到 li 标签。如果画廊部分在屏幕上,则添加活动类并从前一个 li 中删除活动类。
我必须更改颜色并将底部边框添加到活动菜单列表中。我不想使用任何插件。
这是一个例子。它正在添加活动类并更改导航列表的颜色 https://blackrockdigital.github.io/startbootstrap-scrolling-nav/
可以使用 jQuery 吗?
$(function() {
$('.smothscrollclass a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top - 100
}, 1000);
return false;
}
}
});
});
body {
margin: 0;
padding: 0;
}
.headerMenu {
position: fixed;
top: 0;
width: 100%;
background-color: #d9a6a6;
}
.anchorLinks ul {
list-style: none;
}
.anchorLinks ul li {
display: inline-block;
margin: 15px;
}
.anchorLinks ul li a {
color: #fff;
text-decoration: none;
font-size: 18px;
}
.anchorLinks ul li.active a {
color: #ffef00;
border-bottom: 1px solid #000;
}
.WrapperInner {
margin-top: 80px;
margin-bottom: 80px;
}
section {
height: 400px;
padding: 40px;
}
section p {
color: #fff;
}
.aboutus {
background-color: #ec7063;
}
.service {
background-color: #a569bd;
}
.gallery {
background-color: #5dade2;
}
.contactus {
background-color: #2ecc71;
}
<div class="Wrapper">
<div class="mainInner bg_white">
<div class="linkWrappers">
<header class="headerMenu">
<div class="anchorLinks smothscrollclass">
<ul>
<li><a href="">Home</a></li>
<li><a href="#aboutus">About</a></li>
<li><a href="#service">Service</a></li>
<li><a href="#gallery">Gallery</a></li>
<li><a href="#contactus">Contact</a></li>
</ul>
</div>
</header>
</div>
宝慕林4294392
红颜莎娜
温温酱
缥缈止盈
随时随地看视频慕课网APP
相关分类