移动端响应式菜单链接无法正常工作技术求助
Hey there, let's troubleshoot that mobile menu link issue on bonburger.ca. Based on the code snippet you shared and common mobile menu pitfalls, here are actionable fixes to get those links working:
1. Fix JavaScript Event Conflicts
Mobile menus often rely on JS to toggle submenus, and it’s easy to accidentally block link clicks with overzealous event handling:
- Check if your code uses
preventDefault()orstopPropagation()on parent<a>elements (like the one with the dropdown icon). If so, restrict this behavior to only the dropdown trigger, not the actual navigation links. - Example adjustment: Add a class like
has-submenuto the parent link, then target only that class in your JS:$('.has-submenu').click(function(e) { // Only block default action on mobile screens if (window.innerWidth < 768) { e.preventDefault(); $(this).next('.sub-list').toggleClass('active'); // Toggle submenu visibility } // Desktop will follow the link normally });
2. Check for pointer-events CSS Blocking
Sometimes CSS can accidentally make links unclickable. Inspect your stylesheet to ensure:
.sub-list li aor related elements don’t havepointer-events: none(a common mistake when hiding submenus).- If you use this property to hide collapsed menus, set
pointer-events: autowhen the menu is expanded.
3. Verify Z-Index Hierarchy
It’s possible another element (like a header overlay or background div) is sitting on top of your mobile menu links, blocking clicks:
- Open your browser’s dev tools (F12), select the link element, and check its
z-indexvalue. - Ensure the menu container (
#res-menu) has a higher z-index than any overlapping elements (e.g.,z-index: 9999).
4. Clean Up HTML Structure
Your current parent link both points to home.html and triggers a submenu—this can cause confusion on mobile:
- If the parent link only needs to toggle the submenu (not navigate), remove the
hrefattribute or set it tohref="#"(and handle the toggle via JS). - If you want it to navigate and toggle, use the JS logic from point 1 to differentiate between mobile and desktop behavior.
5. Test Touch Event Compatibility
Mobile devices prioritize touch events over click events in some cases. Update your event listeners to support both:
$('.menu-panel a').on('click touchstart', function(e) { // Add your menu toggle logic here, making sure links aren’t blocked unnecessarily });
内容的提问来源于stack exchange,提问作者Justin Wellman




