codrops / Blueprint-HorizontalDropDownMenu

A responsive horizontal drop-down menu inspired by the Microsoft.com menu.
99 stars 65 forks source link

Hover #2

Open alimosavifard opened 11 years ago

alimosavifard commented 11 years ago

Hi , Can i have a menu hover (not click) action (open , close) ,

chrisdivyak commented 10 years ago

You can do it by changing the init() function parameters to 'mouseover' instead of 'click.'

function init() {
        $menuItems.on( 'mouseover', open );
        $listItems.on( 'click', function( event ) { event.stopPropagation(); } );
    }
Maby commented 8 years ago

Hi, is there a possibility to have some delay before the hover effect? I don't want to the menu hover appear by mistake

chrisdivyak commented 8 years ago

Yes, you can add a setTimeout function after the open function. Replace the function open(event){...} with the following:

function open( event ) {
    setTimeout(function(){
        if( current !== -1 ) {
            $listItems.eq( current ).removeClass( 'cbp-hropen' );
        }
        var $item = $( event.currentTarget ).parent( 'li' ),
            idx = $item.index();
        if( current === idx ) {
            $item.removeClass( 'cbp-hropen' );
            current = -1;
        }
        else {
            $item.addClass( 'cbp-hropen' );
            current = idx;
            $body.off( 'click' ).on( 'click', close );
        }
        return false;
    }, 500);
}
Maby commented 8 years ago

Works fine, thank you for your rapid answer ;)

unatalandrea commented 7 years ago

Hi, can I close menu on mouseleave or mouseout?

chrisdivyak commented 7 years ago

You should be able to do this by just adding to the init() function and appending a new variable for the nav. I tested it and it seems to work.

var $listItems = $( '#cbp-hrmenu > ul > li' ),
      $menuItems = $listItems.children( 'a' ),
      $body = $( 'body' ),
      $nav = $( 'nav' ),
      current = -1;
    function init() {
        $menuItems.on( 'mouseover', open );
        $nav.on('mouseleave', close);
        $listItems.on( 'click', function( event ) { event.stopPropagation(); } );
    }