E
E
Edward V.2014-11-21 12:28:26
JavaScript
Edward V., 2014-11-21 12:28:26

How to fix menu flickering in bootstrap when using hover effect and javascript?

Hello.
I was looking for a way to implement a dropdown menu with hover effect in bootstrap 3.
I found this solution:

$( document ).ready(function() {
      $( 'ul.nav li.dropdown' ).hover(function() {
         // $( window ).width() >= 768
        if ($('.navbar-toggle').css('display') === 'none' 
            && false === ('ontouchstart' in document)) {

            $( '.dropdown-toggle', this ).trigger( 'click' );
        }
      }, function() {
        if ($('.navbar-toggle').css('display') === 'none'
            && false === ('ontouchstart' in document)) {

            $( '.dropdown-toggle', this ).trigger( 'click' );
        }
     });
});

The problem is that when you click on a menu item or on the drop-down block itself, it, the block, flickers.
I posted an example - jsfiddle.net/V_E_Y/85qan7qt/20
​​Do not tell me what could be the reason, how to solve this problem?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asdz, 2014-11-21
@asdz

Quick: remove your js and add

ul.nav li.dropdown:hover > .dropdown-menu {
    display: block;    
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question