Skip to content

Instantly share code, notes, and snippets.

@Scretch-1
Last active June 7, 2016 04:55
Show Gist options
  • Save Scretch-1/840ca9777305692ce0d1 to your computer and use it in GitHub Desktop.
Save Scretch-1/840ca9777305692ce0d1 to your computer and use it in GitHub Desktop.
jQ Dropdown (выпадающий список) (custom default)
//--HTML--//
<ul class="dropdown-menu">
<li>
<a class="dropdown-toggle" href="#" title="Menu">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>
</li>
</ul>
//--end HTML--//
//--CSS--//
// Dropdown menu
.dropdown-menu {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
}
.dropdown-toggle {
padding: 5px 10px;
background: #fff;
}
ul.dropdown {
display:none;
position: absolute;
top: 100%;
background: #d6d6d6;
min-width: auto;
padding: 0;
li {
list-style-type: none;
a {
text-decoration: none;
padding: 5px 10px;
display: block;
}
}
}
//--end CSS--//
//--JS--//
$(function() {
// Dropdown toggle
$('.dropdown-toggle').click(function(){
$(this).next('.dropdown').toggle();
});
$(document).click(function(e) {
var target = e.target;
if (!$(target).is('.dropdown-toggle') && !$(target).parents().is('.dropdown-toggle')) {
$('.dropdown').hide();
}
});
});
//--end JS--//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment