A fork of Scott Bolinger's simple jquery dropdown menu. It isn't hidden when clicked away.
Created
February 23, 2022 10:54
-
-
Save iamhtmldeveloper/e6bd3127fc77feb14a6f14a53c4f9778 to your computer and use it in GitHub Desktop.
Simple jQuery Drop Down Menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="nav"> | |
<a class="dropdown-toggle" href="#">Menu</a> | |
<ul class="dropdown"> | |
<li><a href="#">Menu Item</a></li> | |
<li><a href="#">Menu</a></li> | |
<li><a href="#">Settings</a></li> | |
<li><a href="#">Search</a></li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { // Dropdown toggle | |
$('.dropdown-toggle').click(function() { $(this).next('.dropdown').slideToggle(); | |
}); | |
$(document).click(function(e) | |
{ | |
var target = e.target; | |
if (!$(target).is('.dropdown-toggle') && !$(target).parents().is('.dropdown-toggle')) | |
//{ $('.dropdown').hide(); } | |
{ $('.dropdown').slideUp(); } | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { padding: 2em; } a { text-decoration: none; color: #fff; } | |
/**** ****/ | |
div#nav { position: relative; } div#nav a { padding: 5px 15px 5px; } | |
.dropdown-toggle { padding: 0; background: #777; } | |
/**** ****/ | |
ul.dropdown { display: none; position: absolute; top: 100%; | |
margin-top: 5px; padding: 5px 5px 0 0; background: #777; } | |
ul.dropdown li { list-style-type: none; } | |
ul.dropdown li a { text-decoration: none; padding: 0em 1em; display: block; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment