Skip to content

Instantly share code, notes, and snippets.

@apfelbox
Last active January 4, 2016 00:19
Show Gist options
  • Save apfelbox/8541060 to your computer and use it in GitHub Desktop.
Save apfelbox/8541060 to your computer and use it in GitHub Desktop.
Add Bootstrap hover dropdowns and make dropdown-toggle item clickable.1. Just don't add `data-toggle="dropdown"`2.1 JS: Load this code (hover-navbar.js)2.2 CSS: Add this code (hover-navbar.css)(not both, just one of them)
(function ($)
{
"use strict";
$(".navbar .nav")
.on("mouseenter", "li.dropdown", onMouseEnter)
.on("mouseleave", "li.dropdown", onMouseLeave);
/**
* Callback on mouse enter
*
* @param event
*/
function onMouseEnter (event)
{
showDropdown( $(event.currentTarget) );
}
/**
* Callback on mouse leave
*
* @param event
*/
function onMouseLeave (event)
{
hideDropdown( $(event.currentTarget) );
}
/**
* Shows the dropdown of the given element
*
* @param $li {jQuery}
*/
function showDropdown ($li)
{
$li.children(".dropdown-menu").show();
}
/**
* Hides the dropdown of the given element
*
* @param $li {jQuery}
*/
function hideDropdown ($li)
{
$li.children(".dropdown-menu").hide();
}
}(jQuery));
.navbar .nav li.dropdown:hover {
.dropdown-menu {
display: block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment