[英]Console has “Cannot read property ”top“ of undefined error”
I'm trying to use Bootstrap affix on my navbar to get it fixed on top, once it's been reached by scrolling down. 我试图在导航栏上使用Bootstrap词缀将其固定在顶部,一旦通过向下滚动到达该词缀即可。
HTML: HTML:
<div id="nav-wrapper">
<div class="container"><!--container-->
<div class="row" id="navigation"><!--header-->
<div class="col-md-12"><!--col-md-12-->
<div class="navbar" id="nav"><!--nav-->
<div class="menu-main-menu-container">
<ul id="menu-main-menu" class="menu">
<li><a href="http://endurancefilmsti.com/">Home</a></li>
<li><a href="http://endurancefilmsti.com/about-efti/">About EFTI</a></li>
<li><a href="http://endurancefilmsti.com/our-coaches/">Our Coaches</a></li>
<li><a href="http://endurancefilmsti.com/blog/">Blog</a></li>
<li><a href="http://endurancefilmsti.com/efti-forum/">EFTI Forum</a></li>
<li><a href="http://endurancefilmsti.com/contact-us/">Contact Us</a></li>
</ul>
</div>
</div><!--nav-->
</div><!--col-md-12-->
<div class="clearfix"></div>
</div><!--header-->
</div><!--container-->
</div>
JS: JS:
$(function() {
$('#nav-wrapper').height($("#nav").height());
$('#nav').affix({
offset: { top: $('#nav').offset().top }
});
});
I have set the position for the nav in my CSS, as required by Bootstrap documentation. 根据Bootstrap文档的要求,我已经在CSS中设置了导航的位置。
#nav.affix {
position: fixed;
top: 0;
width: 100%;
}
#nav > .navbar-inner {
border-left: 0;
border-right: 0;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
-o-border-radius: 0;
}
Twitter Bootstrap has a class .navbar-fixed-top
which you could apply to your div with the class .navbar
. Twitter Bootstrap具有
.navbar-fixed-top
,您可以使用.navbar
类将其应用于div。
I would imagine that would do the trick for you. 我想这会帮到您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.