On large screens, I want dropdowns to appear on hover, but on mobile I want to arrange them like accordions.
My jQuery is conflicting with my CSS. On mobile, clicking the li
creates all kinds of problems: the event fires over and over, and if I resize to larger viewport, the dropdown remains open and the :focus
and :hover
rules are disabled.
Sass
// If bigger screen, show the submenu on hover or focus
ul.sub {
display: none;
}
body.desktop {
li.dropdown:hover,
li.dropdown:focus {
> ul.sub {
dispay: block;
}
}
}
JavaScript
if ($('body.desktop').length < 1) {
$('li.dropdown > a').on('click', function(e){
$(this).parent().find('.dropdown-menu').slideToggle('fast');
e.preventDefault();
});
} else {
return false;
}