So on the project I am on, I wanted the parent items of my navigation to be clickable, along with the dropdown appearing on :hover.
I found this jquery script and it worked great for that:
<script>
jQuery(function($) {
if($(window).width()>992){
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$('.navbar .dropdown > a').click(function(){
location.href = this.href;
});
}
});
</script>
However two problems arose with this:
- When the viewport is greater than 992px and I resize the browser <992px the hover effect retains even though I would like the dropdown to appear when active at less than 992px. Is there a way to detect the resizing of the viewport to fix this?
- When the viewport is less than 992px the parent items no longer work. Is there a way to possibly make the parent item clickable on a double click? I'd like it this way because people on mobile/tablet can tap once for dropdown and twice for the parent item.
This is my first stackoverflow posting and I would really appreciate any help anyone has to offer. Thank you.