I'd like to have my Bootstrap menu automatically drop down on hover, rather than having to click the menu title. I'd also like to lose the little arrows next to the menu titles.
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- How to add a “active” class to a carousel first el
- Add animation to jQuery function Interval
- jQuery hover to slide?
I have published a proper plugin for the Bootstrap 3 dropdown hover functionality, in which you can even define what happens when clicking on the
dropdown-toggle
element (the click can be disabled):https://github.com/istvan-ujjmeszaros/bootstrap-dropdown-hover
Why I made it when there are many solutions already?
I had issues with all the previously existing solutions. The simple CSS ones are not using the
.open
class on the.dropdown
, so there will be no feedback on the drop-down toggle element when the drop-down is visible.The js ones are interfering with clicking on
.dropdown-toggle
, so the dropdown shows up on hover, then hides it when clicking on an opened drop-down, and moving out the mouse will trigger the drop-down to show up again. Some of the js solutions are breaking iOS compatibility, some plugins are not working on modern desktop browsers which are supporting the touch events.That's why I made the Bootstrap Dropdown Hover plugin which prevents all these issues by using only the standard Bootstrap javascript API, without any hack. Even the Aria attributes are working fine with this plugin.
To enhance Sudharshan's answer, I wrap this in a media query to prevent the hover when on XS display widths...
Also the caret in the markup is not required, just the dropdown class for the li.
This will hide the up ones
The jQuery solution is good, but it will need to either deal with on click events (for mobile or tablet) as hover won't work properly... Could maybe do some window re-size detection?
Andres Ilich's answer seems to work well, but it should be wrapped in a media query:
This is built into Bootstrap 3. Just add this to your CSS:
I created a pure on hover dropdown menu based on the latest (v2.0.2) Bootstrap framework that has support for multiple submenus and thought I'd post it for future users:
Demo