gpt4 book ai didi

javascript - 粘性导航栏不工作

转载 作者:太空宇宙 更新时间:2023-11-03 20:42:16 25 4
gpt4 key购买 nike

我一直在尝试在我的元素中实现粘性导航栏,但不知何故它不起作用。我不知道这里出了什么问题(PS:它甚至没有出现在我的 fiddle 中,但确实出现在我正在构建的本地文件中。)

一直在使用 twitter bootstrap 3.x。可能出了什么问题?如果能提供一点帮助,我们将不胜感激。

这是我正在实现的代码:

HTML:

<div class="container-fluid">

<h3>this is a title</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc molestie posuere justo id condimentum. Morbi eu massa non enim varius lobortis vitae id massa. Aliquam congue consectetur nisi, sit amet tempus nunc mattis at. Aliquam non eleifend quam, ac accumsan urna. Nullam porta metus lacus, aliquam pretium purus rhoncus et. Donec in congue mi. Integer eu massa tincidunt, convallis diam in, ultrices lacus. Nulla bibendum metus sed enim faucibus, vel egestas tortor sollicitudin. Proin bibendum condimentum enim, ac luctus augue gravida et. Proin pretium tortor sed turpis gravida molestie. In hac habitasse platea dictumst.</p>
</div>
<div id="navi" class="navbar navbar-inverse visible-md visible-lg" role="navigation">
<ul class="nav navbar-nav">
<li><a href="#">Home</a>

</li>
<li class="active"><a href="#about">About me</a>

</li>
<li><a href="#resume">Resume</a>

</li>
<li><a href="#contact">Contact</a>

</li>
</ul>
</div>
<p>lol Proin auctor turpis ac elit pharetra laoreet. Cras consequat mauris ut condimentum vulputate. Nunc faucibus viverra suscipit. Sed sit amet ante interdum libero malesuada adipiscing sed at erat. Praesent et tristique lorem. Vestibulum lobortis laoreet tortor eget pellentesque. Nam commodo nibh libero, in elementum mi lobortis ut. this is a title Pellentesque interdum, quam sit amet sagittis porttitor, nunc lorem aliquam lorem, varius laoreet lectus diam vel mi. Fusce ut justo a neque vestibulum aliquam ac at ante. Phasellus porttitor mollis semper. Cras ultricies augue augue, non consequat nisi laoreet et. Donec sapien erat, molestie in faucibus ut, dapibus id risus. Morbi nec lorem nulla. Suspendisse potenti. Ut congue purus vel tincidunt facilisis. Cras condimentum lorem a purus lacinia dignissim. Curabitur convallis, leo ut vestibulum feugiat, ante urna ullamcorper ipsum, et aliquam justo sem ac urna. Praesent rhoncus risus nec dignissim ornare. Sed nec tellus nibh. Nulla in mauris ac lorem mollis ultricies id et mauris.</p>

CSS:

.fixed {
position: fixed;
top: 0;
height: 50px;
z-index: 180;
}

jQuery

 $(document).ready(function(){
$(window).bind('scroll', function() {
var navHeight = $( window ).height() - 50;
if ($(window).scrollTop() > navHeight) {
$('#navi').addClass('fixed');
}
else {
$('#navi').removeClass('fixed');
}
});
});

The Fiddle Link

提前致谢

最佳答案

将以下代码添加到您的 css

#navi{
display: block!important;
}

这是因为 bootstrap 以某种方式使你的 nav display:none

Working Code

关于javascript - 粘性导航栏不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24731067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com