I wanted a solution that was implemented in vanilla js and disabled hovers on the mobile devices. You will need to change the selector to match that of the target you have in mind.
Last active
February 9, 2019 13:32
-
-
Save pigeonflight/733276299fdd0faea7d8678ec35f7359 to your computer and use it in GitHub Desktop.
Hover Menu Fix for Mobile Devices - disable menu hover on touch devices (Vanilla JS implementation)
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
function is_touch_device() { | |
return !!('ontouchstart' in window); | |
} | |
document.addEventListener("DOMContentLoaded", function() { | |
/* If mobile browser, prevent click on parent nav item from redirecting to URL */ | |
if(is_touch_device()) { | |
// replace the selector with the one that matches your menu item | |
var selector = "a.gl-menu-link.dropdown-toggle"; | |
var menulinks = [].slice.call(document.querySelectorAll(selector)); | |
for (menulink of menulinks){ | |
menulink.addEventListener('click', function(event){ | |
event.preventDefault(); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment