I want to change the default Bootstrap navbar component to a drilldown navigation on mobile. Do do that, I've added some JavaScript code to change my menu.
Here's the code I'm using at the moment: https://codepen.io/cray_code/pen/dENeKM
It works fine but on desktop the menu opens after a click instead an hover event.
For the desktop viewport there is the following code:
$('.mega-menu-trigger').bind('click' ,function(e){
e.preventDefault();
var current = $(this).next('.mega-menu');
$('.mega-menu-trigger').not(this).removeClass('active');
$(this).toggleClass('active');
$('.mega-menu').not(current).removeClass('open').addClass('closed');
if( !current.hasClass('open') ){
current.removeClass('closed').addClass('open');
} else {
current.removeClass('open').addClass('closed');
}
});
I tried to change the code with mouseenter to this:
$('.mega-menu-trigger').bind(mouseenter: function(e){
But that doesn't work and I have the problem that the menu stays open after leaving the link.
I guess I have to work with mouseleave but I couldn't figure out how.
Is there any way to change the menu from click to hover?