Skip to content

Instantly share code, notes, and snippets.

@monkishtypist
Created September 29, 2018 00:18
Show Gist options
  • Save monkishtypist/f3fd446bed515cb8d1dcfaf79cd4e06e to your computer and use it in GitHub Desktop.
Save monkishtypist/f3fd446bed515cb8d1dcfaf79cd4e06e to your computer and use it in GitHub Desktop.
Nav fix for Dropdown gaps (Bootstrap)
/**
* Nav Fix for Dropdown Gaps (Bootstrap)
*
* This jQuery fixes hover state issues when the menu dropdown
* has a gap from its parent nav item, thus closing the dropdown
* before the cursor can span the gap. This adds a slight delay
* to allow the cursor to cross the gap before the dropdown is
* closed.
*/
(function( $ ) {
'use strict';
var timer;
var ref;
$(".nav-item")
.on("mouseover", showDropdown)
.on("mouseleave", function(){
timer = setTimeout( hideDropdown, 250);
});
function showDropdown() {
clearTimeout(timer);
hideDropdown();
ref = $(this);
ref.addClass("show");
}
function hideDropdown() {
if (ref)
ref.removeClass("show");
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment