Skip to content

Instantly share code, notes, and snippets.

@lewebsimple
Created March 20, 2017 23:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewebsimple/6121d35a5977cb036b08c8d9bdb94726 to your computer and use it in GitHub Desktop.
Save lewebsimple/6121d35a5977cb036b08c8d9bdb94726 to your computer and use it in GitHub Desktop.
[Bootstrap 4] Dropdown navbar menu on hover
// Dropdown navbar menu on hover
$('.dropdown-menu', this).css('margin-top', 0);
$('.dropdown').hover(function () {
$('.dropdown-toggle', this).trigger('click').toggleClass("disabled");
});
@milyas77
Copy link

milyas77 commented Jan 2, 2018

i try this it is notworking

@CherenkovS
Copy link

Works. Thanks!

@cevatasln
Copy link

$('.dropdown-toggle').hover(function () { $(this).trigger('click').toggleClass("disabled"); });
I think that's better

@doublejosh
Copy link

doublejosh commented Mar 20, 2018

The second solution avoids the UX annoyance where the menu disappears when you try to re-enter after leaving (because it doesn't catch the original mouseleave event for some reason.

But the menu still stays open after leaving the drop down. Also, there a bad toggle when hovering over the main menu item from the dropdown.

Eventually went this with this, as it avoids all those issues and is pure CSS :)

.dropdown-menu {
  margin: 0;
}
.dropdown:hover > .dropdown-menu {
  display: block;
}

@diaolizhi
Copy link

$('.dropdown-toggle').hover(function () { $(this).trigger('click').toggleClass("disabled"); });
I think that's better

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment