Twitter Bootstrap is now just Bootstrap, and I’ve renamed this repo, renamed the files and change all references from Twitter Bootstrap to just Bootstrap in the docs/example to reflect that.
No actual code changed, so I am keeping the current version (
at the time of this writing), but be aware of the lack of twitter- from the beginning of the JS files and how that might affect you.
Sorry for any inconvenience!
I updated the demo with Bootstrap 3, as well as removed code associated to submenus (not supported in Bootstrap 3) and touch devices (just make sure you have
to let Mobile do its thing and my plugin won’t interfere).
A simple plugin to enable Bootstrap dropdowns to activate on hover and provide a nice user experience.
The dropdowns are dismissed after a configurable delay. This fixes an issue that can instantly close your nav because of a 1px gap between the button/nav item that activated the dropdown and the actual dropdown. It is also generally a better user experience, as users are not punished by going 1 pixel outside of the dropdown, which would instantly close the nav without a delay.
Note: The HTML markup is the same as with any other Bootstrap dropdown. This will not interfere with Bootstrap’s default activate-on-click method (i.e. this plugin combined with Bootstrap’s default behavior work well to support both the ideal experience on desktop and mobile).
bower install bootstrap-hover-dropdown
which will also automatically install Bootstrap and jQuery if needed.
Once you have the files downloaded, link to the files in your code after you include the main Bootstrap JS file(s):
1 2 3 4
<!-- script order matters! --> <script src="/path/to/jquery.min.js"></script> <script src="/path/to/bootstrap.min.js"></script> <script src="/path/to/bootstrap-hover-dropdown.min.js"></script>
in addition (or in place of) Bootstrap’s
You can set options via data-attributes, too, via
. Here’s an example of markup:
1 2 3 4 5 6 7 8 9 10 11 12 13
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="false"> Account <b class="caret"></b> </a> <ul class="dropdown-menu"> <li><a tabindex="-1" href="#">My Account</a></li> <li class="divider"></li> <li><a tabindex="-1" href="#">Change Email</a></li> <li><a tabindex="-1" href="#">Change Password</a></li> <li class="divider"></li> <li><a tabindex="-1" href="#">Logout</a></li> </ul> </li>
This also works with submenus without any other configuring since Bootstrap already supports this feature. Just use the markup like you were using before. Only the top level anchor tag needs any special markup for my plugin to work (see demo for proper markup).
You can view a demo for this plugin on my site: http://cameronspear.com/demos/bootstrap-hover-dropdown/
This plugin purposedly lets you choose a selector (as opposed to apply this to everything with the class of
). This is so that you can selectively apply it where you want. Maybe you only want to use it for the main nav, and not have it activate for dropdown buttons in the main content. You can add a class to the item that normally gets
and use that class with this plugin to easily achieve that, or use a selector such as
Important: Bootstrap relies on styles associated with the class
(for stuff like the caret color), and it is recommended you leave that class alone.
I’m a slacker and only started keeping track of changes/bug fixes starting in March of 2013.
option, as it’s not really relevant.
Mattia Larentis helped me with the idea for the data-attributes and doing the options via an object.
As this plugin, in its simplicity, is pretty much exactly what I intend it to be, I don’t plan to implement any new features.
One exception: I would like to tweak it so that when you’re in a submenu, it doesn’t instantly close when you hover outside of it. Update: I added this in late April 2013.
If you have ideas for a new feature or something along those lines, you’re welcome to share them with me, but I am not likely to implement it/merge your pull without a very compelling reason. You are absolutely free to create a fork and implement the feature yourself for your and others’ use.
This, of course, does not speak for bugs. If you have a bug, please bring it to my attention, and I will try and fix it. Note that 93.7% of people’s issues are caused by incorrect markup, so please double check that first.
Copyright © 2017 Ahead Guest Inc.