admin管理员组文章数量:1327750
I have a navbar which is below the header image. I want the navbar to stick to the top of the webpage when I scroll down. I can't think of the jQuery or CSS required, because the navbar seems to stick right below the header image leaving some gap.
<div class="headerwrap pull-center">
<div class="container">
<div id="header" class="row-fluid">
<div class="span5" id="phones">
<img class="phone" src="img/white.png" alt="">
</div>
<div class="span7" id="mm-logo">
<img class="mm-log" src="img/logo.png" alt="">
</div>
</div>
</div>
</div>
<div class="navbar navbar-inner" id="border-stuff">
<div class="span12">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<!-- Everything you want hidden at 768px or less, place within here -->
<div class="nav-collapse collapse" id="center-nav">
<ul class="nav" >
<li><a href="#h1"><h3>Heading1</h3></a></li><li class="divider-vertical"></li>
<li><a href="#h2"><h3>Heading2</h3></a></li><li class="divider-vertical"></li>
<li><a href="#h3"><h3>Heading3</h3></a></li><li class="divider-vertical"> </li>
<li><a href="#h4"><h3>Heading4</h3></a></li><li class="divider-vertical"></li>
<li><a href="#h5"><h3>Heading4</h3></a></li>
</ul>
</div>
</div>
</div>
I have a navbar which is below the header image. I want the navbar to stick to the top of the webpage when I scroll down. I can't think of the jQuery or CSS required, because the navbar seems to stick right below the header image leaving some gap.
<div class="headerwrap pull-center">
<div class="container">
<div id="header" class="row-fluid">
<div class="span5" id="phones">
<img class="phone" src="img/white.png" alt="">
</div>
<div class="span7" id="mm-logo">
<img class="mm-log" src="img/logo.png" alt="">
</div>
</div>
</div>
</div>
<div class="navbar navbar-inner" id="border-stuff">
<div class="span12">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<!-- Everything you want hidden at 768px or less, place within here -->
<div class="nav-collapse collapse" id="center-nav">
<ul class="nav" >
<li><a href="#h1"><h3>Heading1</h3></a></li><li class="divider-vertical"></li>
<li><a href="#h2"><h3>Heading2</h3></a></li><li class="divider-vertical"></li>
<li><a href="#h3"><h3>Heading3</h3></a></li><li class="divider-vertical"> </li>
<li><a href="#h4"><h3>Heading4</h3></a></li><li class="divider-vertical"></li>
<li><a href="#h5"><h3>Heading4</h3></a></li>
</ul>
</div>
</div>
</div>
Share
Improve this question
edited Nov 10, 2015 at 9:27
Sebastian Zartner
20.1k10 gold badges102 silver badges141 bronze badges
asked Jul 16, 2013 at 21:17
user2441391user2441391
3391 gold badge5 silver badges17 bronze badges
1
- 3 it would be nice if you had a jsfiddle.. – Yannis Dran Commented Mar 11, 2014 at 22:38
2 Answers
Reset to default 20If you want your navbar to stay fixed at the top of the screen only once the header image has scrolled away you can use the bootstrap affix plugin.
You just need to replace your Jquery code to this:
$('#sidebar').affix({
offset: {
top: 50
}
});
And adjust the top to whatever fits best.
本文标签: javascriptBootstrapmake a navbar sticky after scrolling downStack Overflow
版权声明:本文标题:javascript - Bootstrap, make a navbar sticky after scrolling down? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739027888a2134887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论