Bootstrap 3: Collapse on Hover and fixed on click

Asked

Viewed 265 times

3

I would like to know how to make the Collapse of Bootstrap 3 open in the Hover and if it is clicked it is fixed (Do not close) and only close if another Collapse is clicked (And this other Collapse open).

With the following code I managed to get it to open in the Hover, but I can’t fix it in the click.

// Classe .menu-header abraça todo o collapse para que ele nao feche ao retirar o hover do botão.
$('.menu-header').hover(function () { 
    $('#administrativoCollapse').toggleClass('in');
});
  • I didn’t quite understand your question, the standard Collapse already leaves the div that will appear fixed, you want the Hover it appears and then close the onClick stay fixed?

  • That, the Collapse pattern is in the first click it opens and in the second it closes, I would like it to open/close in Hover and in case the user of a click it stays open even if the pointer is no longer in Hover.

1 answer

2


You can use the following code so that when you click, in addition to you set the class to leave it open, you remove the event from Hover.

$('.menu-header').click(function () { 
    $('#administrativoCollapse').toggleClass('in');
    $('#menu-header').off('hover');
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.