gpt4 book ai didi

javascript - 如何修复 Nav 和 Tab 两者

转载 作者:太空宇宙 更新时间:2023-11-04 07:14:46 26 4
gpt4 key购买 nike

http://jsfiddle.net/L1bns58m/1/

脚本被编程为检查我的选项卡是否在顶部。如果 top 只是通过更新/添加类 sticky 来修复它。

代码:

// This is my javaScript Code ....
// which will check whether my tab is on the top or not... if top just fixed
// it by updating/ adding the class sticky.
window.onscroll = function() {cFunction()};

var header = document.getElementById("myHeader");
var sticky = header.offsetTop;

function cFunction() {
if (window.pageYOffset >= sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
.btn-primary
{
font-size:12px;
}
.btn-group-justified {
width:100%;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}

.sticky + .content {
padding-top: 102px;
}

.section{
width:100%;
}

}
}</script>

</body>
</html>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</nav>
<!-- MY Tab Code below the NAV Section

This is My tab bar consisting of bootstrap button group. -->

<section>
<div class="container" id="myHeader">
<div id="no" class="btn-group btn-group-justified">
<a href="#" class="btn btn-primary">Rates</a>
<a href="#" class="btn btn-primary">What to Expect</a>
<a href="#" class="btn btn-primary">Our Professionals</a>
</div>

<div id="yes" class="btn-group btn-group-justified">
<a href="#" class="btn btn-primary">Reviews</a>
<a href="#" class="btn btn-primary">Recent Bookings</a>
<a href="#" class="btn btn-primary">FAQs</a>
<a href="#" class="btn btn-primary">Related Blogs</a>

</div>
</div>
</section>

如何修复导航栏和标签?实际上,我想将标签栏固定在导航栏下方。
我只是尝试将顶部从 0 更改为某个 +ve 值,但没有任何改变。还使用了 position :fixed。

最佳答案

好吧,一方面,我检查了您的 CSS,但没有发现任何与类“nav”、“navbar-nav”或类似内容相关的内容。您完成导航栏的样式设计了吗?我在任何地方都看不到 CSS。

.btn-primary
{
font-size:12px;
}
.btn-group-justified {
width:100%;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}

.sticky + .content {
padding-top: 102px;
}

.section{
width:100%;
}

}
}</script>

</body>
</html>

此外,我知道这不能回答您的问题,但是您的 JavaScript 给了我一个“意外的输入错误结束”,因为显然当我将它放入控制台时,if...else 代码块。你可能想确保你没有忘记最后两个右括号,如果它工作正常那么它一定是我......

关于javascript - 如何修复 Nav 和 Tab 两者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50819467/

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