我进行了搜索和搜索,似乎无法找到我的问题。如果在其他地方得到回答,我道歉。我继承了一个需要实现scrolllspy的“简单”网站,我无法为我的生活做任何事情。
以下是代码的一些摘录:
HTML NAV
<div class="row" style="width:100%" id="topnav">
<nav id="anchored" role="navigation">
<a href="#top" class="logo"></a>
<ul class="nav top-menu fade-in">
<li class="mission_anchor"><a href="#services" class="">SERVICES</a></li>
<li class="stories"><a href="#about" class="">ABOUT</a></li>
<li class="supporters_anchor"><a href="#demo" class="">REQUEST DEMO</a></li>
</ul>
</nav>
</div>
<br />
第一个“服务DIV”样本
<section class="module content">
<div id="services" class="row">
<div class="col-md-6 col-md-offset-3 text-center">
<h1>HOW SUPER AGENT MARKETING CAN HELP YOUR AGENTS</h1>
<br />
JAVASCRIPT
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$("#topnav").on("activate.bs.scrollspy", function(){
alert('smomething happened')
});
$('#topnav').affix({
offset: {
top: 0
}
});
$('body').scrollspy({ target: '#topnav' });
<br />
可在此处找到完整的演示网站:Demo Site
任何帮助都会非常感激,因为我确信它可能是我看不到的东西,但是在6小时内无法找到它。
答案 0 :(得分:1)
为了使用bootstrap scrollspy你的导航必须作为bootstrap的导航。 建立你的资产净值作为下面这个链接,它将工作 http://getbootstrap.com/components/#navbar
尝试以下示例。
$(function(){
$('body').scrollspy({ target: '#myNav' })
})
section > div[id]{
height:800px;
padding-top:50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<nav id="myNav" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="mission_anchor active"><a href="#services" class="">SERVICES</a></li>
<li class="stories"><a href="#about" class="">ABOUT</a></li>
<li class="supporters_anchor"><a href="#demo" class="">REQUEST DEMO</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<section class="module content">
<div id="services" class="row">
<div class="col-md-6 col-md-offset-3 text-center">
<h1>Services Section</h1>
</div>
</div>
<section>
<section class="module content">
<div id="about" class="row">
<div class="col-md-6 col-md-offset-3 text-center">
<h1>About Section</h1>
</div>
</div>
<section>
<section class="module content">
<div id="demo" class="row">
<div class="col-md-6 col-md-offset-3 text-center">
<h1>Demo Section</h1>
</div>
</div>
<section>