我需要如图所示的导航栏。使用关闭按钮从右向左切换。我已经尝试了一切,并搜索无处不在。提前致谢。 https://imgur.com/a/cIFMYNz
答案 0 :(得分:0)
使用这样的导航栏
$(document).on("click", "#hide-navbar, #show-navbar", function() {
$("#navbarsExample04").toggleClass("d-none");
$("#hide-navbar").toggleClass("d-none");
$("#show-navbar").toggleClass("d-none");
})
.navbar-collapse.collapse.d-none,
#hide-navbar.d-none,
#show-navbar.d-none {
display: none !important;
}
.navbar-expand #show-navbar.navbar-toggler {
display: block;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/eed659c9d4.js"></script>
<nav class="navbar navbar-expand bg-transparent">
<a class="navbar-brand" href="#"><img src="https://picsum.photos/50/30"> ABC</a>
<div class="navbar-collapse collapse" id="navbarsExample04" style="">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
<button class="navbar-toggler d-block ml-auto" type="button" id="hide-navbar">
<span class="fa fa-times"></span>
</button>
<button class="navbar-toggler d-none ml-auto" type="button" id="show-navbar">
<span class="fa fa-bars"></span>
</button>
</nav>