当你点击scrollspy链接时,你怎么能折叠自助汉堡的菜单?
如果在智能手机上查看我的网站时,引导导航被简化为汉堡菜单,并且您单击指向my index.html中特定位置的链接(如#aboutme),而不是指向外部.html页面,则导航将保持打开状态。我希望以后它会再次崩溃。
您可以在以下位置查看代码:https://github.com/senkvalentin/personal_page
或浏览以下网址:https://senkvalentin.com/
以下是我的html的一部分:
<div data-spy="scroll" data-target=".navbar" data-offset="50">
<div class="container">
<div class="row"><nav class="navbar fixed-top navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/"><img src="./img/logo.png" alt="">
</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" aria-current="page" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#aboutMe">About</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#projectsList">Projects</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Admin
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="!#" target="_blank">Server - Info</a></li>
<li><a class="dropdown-item" href="#" target="_blank">Mail - Server</a></li>
<li><a class="dropdown-item" href="#" target="_blank">Mail - Server</a></li>
<li><a class="dropdown-item" href="!#" target="_blank">Cloud - Server</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav></div>
我已经看过了:如何在单击时隐藏可折叠的引导导航栏
并且:当您单击其中的链接时,引导面板塌陷
但什么都没用
即时通讯使用:
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
提前谢谢
1条答案
按热度按时间mu0hgdu01#
在jquery中,只要在单击链接时触发单击导航栏切换按钮即可