You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

移动端响应式菜单链接无法正常工作技术求助

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() or stopPropagation() 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-submenu to 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 a or related elements don’t have pointer-events: none (a common mistake when hiding submenus).
  • If you use this property to hide collapsed menus, set pointer-events: auto when 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-index value.
  • 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 href attribute or set it to href="#" (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

火山引擎 最新活动