Is there a way to make the side nav
close when clicked outside of it while using my left side bar
?
Here is the code for my side nav
:
//side-nav is the class of my side nav
//leftmenutrigger is my button on the nav bar that toggles the side nav
Any suggestions or tips, whether in JavaScript or CSS, on how to hide my side nav bar are appreciated.
Below are the codes for my navigation bar and left side nav bar:
$( document ).ready(function() {
$('.leftmenutrigger').on('click', function(e) {
$('.side-nav').toggleClass("open");
e.preventDefault();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar header-top sticky-top navbar-expand-lg navbar-light bg-light" >
<span class="navbar-toggler-icon leftmenutrigger"></span>
<a class="navbar-brand" href="#">
<img src="images/nexuslogo.png" style="width: 40px; height: 40px;padding: 0px; margin: 0px;">
</a>
<a class="navbar-brand" id="comp_name" name="comp_name"> Nexus Technologies, Inc.</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon" ></span> </button>
<div class="collapse navbar-collapse" id="navbarText" name="navbarText" >
<ul class="navbar-nav animate side-nav ">
<li class="nav-item">
<a href="" id="addUser" name="addUser" style="width: 100%">
<i class="fa fa-plus-circle"></i> Add User
</a>
<a href="manageprize.php" id="manage_prize" name="manage_prize" style="width: 100%" target="_self">
<i class="fa fa-table"></i> Manage Prizes
</a>
</li>
</ul>
</div>
</nav>
THANKS!!!!