Last active
September 5, 2025 09:04
-
-
Save jpneey/ae60e5855802000db932dc983e03530b to your computer and use it in GitHub Desktop.
Toggle bootstrap dropdowns on mousenter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(function($){ | |
| var selector = '.echo-dropdown-toggle'; // your mega menu link selector | |
| var hoverDelay = 200; // ms before menu opens | |
| var hoverTimer; | |
| // Detect touch-capable devices | |
| function isTouchDevice() { | |
| return ( 'ontouchstart' in window ) | |
| || (navigator.maxTouchPoints > 0) | |
| || (navigator.msMaxTouchPoints > 0); | |
| } | |
| function closeAllDropdowns() { | |
| $(selector).each(function() { | |
| $(this).dropdown('hide'); | |
| }); | |
| } | |
| // Only run hover intent on non-touch devices | |
| if (!isTouchDevice()) { | |
| $('body').on('mouseenter', selector, function() { | |
| var $this = $(this); | |
| clearTimeout(hoverTimer); | |
| hoverTimer = setTimeout(function(){ | |
| closeAllDropdowns(); | |
| $this.dropdown('show'); | |
| }, hoverDelay); | |
| }); | |
| $('body').on('mouseleave', selector, function() { | |
| clearTimeout(hoverTimer); | |
| closeAllDropdowns(); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment