当在div之后向下滚动导航条时,导航条会得到一个新的背景颜色(导航条应该固定在顶部,我在引导中使用navbar fixed top
)。
我尝试过一些教程,但没有成功。
我有两个菜单#scroll菜单
和#main菜单
。当我打开浏览器时,我想显示#main菜单
。当我向下滚动#main菜单
时,不显示。显示#scroll菜单
。
<div class="container-fluid">
<nav class="navbar navbar-expand-lg navbar-light bg-light" id="main-menu">
<div class="container-fluid">
<a class="navbar-brand" href="#">لوگو</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">محصولات</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">خدمات</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">راهکارها</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">درباره ما</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">شبکه دانش</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<nav class="navbar navbar-expand-lg navbar-dark bg-blue position-fixed w-100 d-none" id="scroll-menu">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContentFixed" aria-controls="navbarSupportedContentFixed" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContentFixed">
<ul class="navbar-nav me-auto mb-2 mb-lg-0 w-100">
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="far fa-lightbulb"></i>
<span>معرفی</span>
</a>
</li>
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="fas fa-dolly"></i>
<span>انبار و حسابداری انبار</span>
</a>
</li>
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="far fa-building"></i>
<span>دارایی های ثابت</span>
</a>
</li>
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="fas fa-tasks"></i>
<span>صورت های مالی اساسی</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
剧本
window.onscroll = function() {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 700 || document.documentElement.scrollTop > 700) {
document.getElementById('scroll-menu').classList.add("d-none");
document.getElementById('main-menu').classList.remove("d-block");
} else {
document.getElementById('scroll-menu').classList.add("d-block");
document.getElementById('main-menu').classList.remove("d-none");
}
} window.onscroll = function() {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 700 || document.documentElement.scrollTop > 700) {
document.getElementById('scroll-menu').classList.add("d-none");
document.getElementById('main-menu').classList.remove("d-block");
} else {
document.getElementById('scroll-menu').classList.add("d-block");
document.getElementById('main-menu').classList.remove("d-none");
}
}
修改的html
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<body style="height:2000px">
<div class="container-fluid">
<nav class="navbar navbar-expand-lg navbar-light bg-light position-fixed d-block" id="main-menu">
<div class="container-fluid">
<a class="navbar-brand" href="#">لوگو</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">محصولات</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">خدمات</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">راهکارها</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">درباره ما</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">شبکه دانش</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark text-white w-100 text-dark d-none" id="scroll-menu">
<div class="container-fluid">
<a class="navbar-brand" style="font-weight:400" href="#">لوگو</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContentFixed" aria-controls="navbarSupportedContentFixed" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContentFixed">
<ul class="navbar-nav me-auto mb-2 mb-lg-0 w-100">
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="far fa-lightbulb"></i>
<span>معرفی</span>
</a>
</li>
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="fas fa-dolly"></i>
<span>انبار و حسابداری انبار</span>
</a>
</li>
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="far fa-building"></i>
<span>دارایی های ثابت</span>
</a>
</li>
<li class="nav-item col-auto">
<a class="nav-link" href="#">
<i class="fas fa-tasks"></i>
<span>صورت های مالی اساسی</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
修改的javascript
window.onscroll = function() {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 700 || document.documentElement.scrollTop > 700) {
document.getElementById('scroll-menu').classList.add("d-block");
document.getElementById('scroll-menu').classList.remove("d-none");
document.getElementById('scroll-menu').classList.add("position-fixed");
document.getElementById('main-menu').classList.add("d-none");
document.getElementById('main-menu').classList.remove("d-block");
document.getElementById('main-menu').classList.remove("position-fixed");
} else {
document.getElementById('scroll-menu').classList.remove("d-block");
document.getElementById('scroll-menu').classList.add("d-none");
document.getElementById('scroll-menu').classList.remove("position-fixed");
document.getElementById('main-menu').classList.remove("d-none");
document.getElementById('main-menu').classList.add("d-block");
document.getElementById('main-menu').classList.add("position-fixed");
}
}
如何设置没有背景色的导航栏? 当在div之后向下滚动导航条时,导航条会得到一个新的背景颜色(导航条应该固定在顶部,我在引导中使用) 我尝试过一些教程,但没有成功。 这是网站:http://attafothman.olympe.in/ 我说的是上面那个黑色导航条。
问题内容: 我想在页面上建立一个导航栏效果,像一样(向下滚动栏变得更小并且徽标更改后)。我在页面上使用bootstrap 3。有没有一种简单的方法可以通过Bootstrap实现它? 问题答案: 粘性导航栏: 要制作粘性导航,您需要将 navbar-fixed-top 类添加到导航中 官方文档 :http : //getbootstrap.com/components/#navbar-fixed-
我的导航栏有一个透明的背景,当用户向下滚动时,我想添加一个不同的背景。 我使用了这个问题的代码:滚动后更改导航条颜色? 我的代码现在如下所示: 当我向下滚动时,一切正常,背景和不透明度适用,但当我向后滚动到顶部时,这种样式仍然存在。我希望它更改回没有背景的默认样式。 谢啦
问题内容: 我正在使用Bootstrap3,并且希望在用户滚动到我页面上的大标题图像时实现此效果。我需要导航栏的背景从透明变为白色。我查看了他们的代码,我知道它是用javascript完成的,甚至我认为它在哪里发生(在JS中查找ID’#main-header’)… 除了不知道高级Javascript之外,我正在寻找一种在滚动到特定点时将其应用于导航栏的方法。我的代码类称为“ navbar”,当它传
我想要一个半透明的状态栏和导航栏,其他颜色不能像蓝色或白色那样半透明 我的代码 活动 状态栏半透明良好,但导航栏颜色不变。为什么? 导航栏
我试图让我的导航栏在滚动时从透明背景变为黑色背景。与此模板类似:https://www.templatemonsterpreview.com/demo/58900.html?_gl=1*vx82om*\uGA*MTC0odazmti4xNJI3NTCxNdQW*\uGA\uFTPyEGT5LY*MTYyNzYwNzQ4Mi40LjEuMTYyNzYwODA2NC40Nw。。 这是我的html: 这