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?
If you have an element with a
dropdown
class like this (for example):Then you can have the dropdown menu to be automatically drop down on hover over, rather than having to click its title, by using this snippet of jQuery code:
Here is a demo
This answer relied on @Michael answer, I have made some changes and added some additions to get the dropdown menu work properly
[Update] The plugin is on GitHub and I am working on some improvements (like use only with data-attributes (no JS necessary). I've leaving the code in below, but it's not the same as what's on GitHub.
I liked the purely CSS version, but it's nice to have a delay before it closes, as it's usually a better user experience (i.e. not punished for a mouse slip that goes 1 px outside the dropdown, etc), and as mentioned in the comments, there's that 1px of margin you have to deal with or sometimes the nav closes unexpectedly when you're moving to the dropdown from the original button, etc.
I created a quick little plugin that I've used on a couple sites and it's worked nicely. Each nav item is independently handled, so they have their own delay timers, etc.
JS
The
delay
parameter is pretty self explanatory, and theinstantlyCloseOthers
will instantly close all other dropdowns that are open when you hover over a new one.Not pure CSS, but hopefully will help someone else at this late hour (i.e. this is an old thread).
If you want, you can see the different processes I went through (in a discussion on the
#concrete5
IRC) to get it to work via the different steps in this gist: https://gist.github.com/3876924The plugin pattern approach is much cleaner to support individual timers, etc.
See the blog post for more.
Even better with jQuery:
This worked for me:
Overwrite bootstrap.js with this script.