Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a delay on bootstrap dropdown

I'm trying to find the most simplistic way of adding a delay on this bootstrap dropdown...http://www.bootply.com/64074 I have tried various methods and scripts but I cant seem to do it. I've added a css line to allow auto dropdown on mouseover.

            <!-- Top Nav -->
                    <div class="navbar hidden-phone well well-small">
                        <div class="navbar-inner header-drop-nav">

                    <!-- 1st dropdown -->
                    <ul class="nav nav-tabs">
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Browse by Destination <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                  <!--  1st Top Nav links -->
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li class="divider"></li>
                            <li class="nav-header">Nav header</li>
                            <li><a href="#">Separated link</a></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                        </li>
                    </ul>

                    <!-- 2nd dropdown -->
                    <ul class="nav nav-tabs pull-middle">
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Browse by Activity <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                  <!-- 2nd Top Nav links -->
                        <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li class="divider"></li>
                            <li class="nav-header">Nav header</li>
                            <li><a href="#">Separated link</a></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                        </li>
                    </ul>

                    <!-- 3rd dropdown -->
                    <ul class="nav nav-tabs">
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Browse by Interest <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                  <!-- 3rd Top Nav links -->
                        <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li class="divider"></li>
                            <li class="nav-header">Nav header</li>
                            <li><a href="#">Separated link</a></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                        </li>
                    </ul>

                    <!-- 4th dropdown -->
                    <ul class="nav nav-tabs">
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Special Offers <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                  <!-- 4th Top Nav links -->
                        <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li class="divider"></li>
                            <li class="nav-header">Nav header</li>
                            <li><a href="#">Separated link</a></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                        </li>
                    </ul>

                    <form class="navbar-form pull-right hidden-tablet">
                        <input class="span3" type="text" placeholder="Search">
                        <button type="submit" class="btn btn-primary">GoSeeDo</button>
                    </form>

                        </div>
                    </div>
like image 258
Tom Rudge Avatar asked Jun 13 '13 10:06

Tom Rudge


3 Answers

This JQuery did the trick! http://www.bootply.com/64081

    jQuery('ul.nav li.dropdown').hover(function() {
              jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn();
            }, function() {
              jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut();
            });
like image 133
Tom Rudge Avatar answered Sep 21 '22 16:09

Tom Rudge


For those that come across this thread later.. check out this great plugin that is Bootstrap 3 compatible and works with nav menus, buttons, button groups etc:

https://github.com/CWSpear/bootstrap-hover-dropdown

like image 31
Nick B Avatar answered Sep 21 '22 16:09

Nick B


If you are using submenus, need to add .first() after .find():

$('div.dropdown').hover(function() {
    $(this).find('.dropdown-menu').first().stop(true, true).delay(100).fadeIn(100);
}, function() {
    $(this).find('.dropdown-menu').first().stop(true, true).delay(200).fadeOut(300);
});
like image 45
marko.crni Avatar answered Sep 18 '22 16:09

marko.crni