Skip to content

Instantly share code, notes, and snippets.

@jpneey
Last active September 5, 2025 09:04
Show Gist options
  • Select an option

  • Save jpneey/ae60e5855802000db932dc983e03530b to your computer and use it in GitHub Desktop.

Select an option

Save jpneey/ae60e5855802000db932dc983e03530b to your computer and use it in GitHub Desktop.
Toggle bootstrap dropdowns on mousenter
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