Blueprint-HorizontalDropDownMenu icon indicating copy to clipboard operation
Blueprint-HorizontalDropDownMenu copied to clipboard

Hover

Open alimosavifard opened this issue 11 years ago • 6 comments

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

alimosavifard avatar Aug 05 '13 12:08 alimosavifard

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(); } );
    }

chrisdivyak avatar Nov 07 '14 18:11 chrisdivyak

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

Maby avatar Sep 30 '16 16:09 Maby

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);
}

chrisdivyak avatar Sep 30 '16 16:09 chrisdivyak

Works fine, thank you for your rapid answer ;)

Maby avatar Oct 05 '16 09:10 Maby

Hi, can I close menu on mouseleave or mouseout?

unatalandrea avatar Sep 22 '17 18:09 unatalandrea

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(); } );
	}

chrisdivyak avatar Oct 05 '17 13:10 chrisdivyak