我在我的项目中添加了bootstrap进行响应式设计。一切都很好,但它会使标题菜单中的ABOUT US处于活动状态,但在页面加载时,HOME仍处于活动状态。但当页面完全加载时,ABOUT US变为活动状态。
我已经从CDN(link)中提取了 Bootstrap 。
下面是从第801行到第830行的引导代码。
b.prototype.process = function() {
var a, b = this.$scrollElement.scrollTop() + this.options.offset,
c = this.getScrollHeight(),
d = this.options.offset + c - this.$scrollElement.height(),
e = this.offsets,
f = this.targets,
g = this.activeTarget;
if (this.scrollHeight != c && this.refresh(), b >= d) return g != (a = f[f.length - 1]) && this.activate(a);
if (g && b < e[0]) return this.activeTarget = null, this.clear();
for (a = e.length; a--;) g != f[a] && b >= e[a] && (void 0 === e[a + 1] || b < e[a + 1]) && this.activate(f[a])
}, b.prototype.activate = function(b) {
this.activeTarget = b, this.clear();
var c = this.selector + '[data-target="' + b + '"],' + this.selector + '[href="' + b + '"]',
d = a(c).parents("li").addClass("active");
d.parent(".dropdown-menu").length && (d = d.closest("li.dropdown").addClass("active")),
d.trigger("activate.bs.scrollspy")
}, b.prototype.clear = function() {
a(this.selector).parentsUntil(this.options.target, ".active").removeClass("active")
};
var d = a.fn.scrollspy;
a.fn.scrollspy = c, a.fn.scrollspy.Constructor = b, a.fn.scrollspy.noConflict = function() {
return a.fn.scrollspy = d, this
}, a(window).on("load.bs.scrollspy.data-api", function() {
a('[data-spy="scroll"]').each(function() {
var b = a(this);
c.call(b, b.data())
})
})
我的HTML代码如下:
<div class="container">
<div class="navbar-header"><div class="slicknav_menu"><margo aria-haspopup="true" tabindex="0" class="slicknav_btn slicknav_collapsed"><span class="slicknav_menutxt"></span><span class="slicknav_icon slicknav_no-text"><span class="slicknav_icon-bar"></span><span class="slicknav_icon-bar"></span><span class="slicknav_icon-bar"></span></span></margo><ul class="slicknav_nav slicknav_hidden" style="display: none;" aria-hidden="true" role="menu">
<li> <a href="#home" role="menuitem" tabindex="-1">Home</a></li>
<li> <a href="#about" role="menuitem" tabindex="-1">About Us</a>
<!-- <ul class="dropdown">
<li><a href="#">Profile</a>
</li>
<li><a href="#">Press</a>
</li>
</ul> -->
</li>
<li> <a href="#" role="menuitem" tabindex="-1">Products </a>
<!-- <ul class="dropdown">
<li><a href="#">Features</a>
</li>
<li><a href="#">Pricing</a>
</li>
<li><a href="#">Customers</a>
</li>
<li><a href="#">Integrations</a>
</li>
</ul> -->
</li>
<li> <a href="#" role="menuitem" tabindex="-1">Services</a> </li>
<li> <a href="#" role="menuitem" tabindex="-1">Support</a>
<!-- <ul class="dropdown">
<li><a href="#">Product Guide</a>
</li>
<li><a href="#">Help</a>
</li>
<li><a href="#">Terms & Privacy</a>
</li>
<li><a href="#">Developers</a>
</li>
</ul> -->
</li>
<li><a href="#" role="menuitem" tabindex="-1">Register</a> </li>
<li><a href="contact-us.php" role="menuitem" tabindex="-1"> Contact Us </a> </li>
</ul></div>
<!-- Stat Toggle Nav Link For Mobiles -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <i class="fa fa-bars"></i> </button>
<!-- End Toggle Nav Link For Mobiles -->
<a class="navbar-brand" href="http://localhost/kornerStone/" style="padding-top: 8px; padding-bottom: 7px;"> <img alt="" src="images/logo.png" class="img-responsive logo" style="margin-top:11px !important;"> </a> </div>
<div class="navbar-collapse collapse">
<!-- Stat Search -->
<!-- End Search -->
<!-- Start Navigation List -->
<ul class="nav navbar-nav navbar-right">
<li class=""> <a href="#" style="padding-top: 20px; padding-bottom: 20px;">Home</a></li>
<li class="active"> <a href="#about" style="padding-top: 20px; padding-bottom: 20px;">About Us</a>
<!--ul class="dropdown">
<li><a href="#">Profile</a>
</li>
<li><a href="#">Press</a>
</li>
</ul-->
</li>
<li> <a href="#service" style="padding-top: 20px; padding-bottom: 20px;">Services</a> </li>
<li><a href="#" style="padding-top: 20px; padding-bottom: 20px;">Register</a> </li>
<li><a href="contact-us.php" style="padding-top: 20px; padding-bottom: 20px;"> Contact Us </a> </li>
</ul>
<!-- End Navigation List -->
</div>
</div>
在这里你可以看到关于我们的li
有一个ACTIVE类。
1条答案
按热度按时间cwdobuhd1#
您需要将类nav-default添加到nav ul容器中,以便将“关于我们”导航显示为活动(https://jsfiddle.net/4jsaq266/1/):