【问题标题】:menu dropdown not showing correctly on mobile菜单下拉菜单在移动设备上未正确显示
【发布时间】:2015-07-19 09:58:01
【问题描述】:

我有一个 drupal 网站。它是响应式的。 在移动设备上,常规菜单应显示在下拉菜单中。但是,当您单击导航时,菜单选项卡会出现在检查元素中,但在屏幕上它只是一个纯蓝色框,您看不到链接。

网站是http://jspca.org.il/

<ul class="menu" style="overflow: hidden; display: block;"><li class="first leaf"><a href="/en" title="" class="active">Home</a></li>
<li class="leaf"><a href="/en/content/about-us" title="About Us">About</a></li>
<li class="expanded"><a href="/en/content/adoption">Adoption</a><ul class="menu"><li class="first leaf"><a href="/en/content/policy" title="">Policy</a></li>
<li class="leaf"><a href="/en/content/contract" title="">Contract</a></li>
<li class="leaf"><a href="/en/dogs" title="">Adopt a Dog</a></li>
<li class="leaf"><a href="/en/Cats" title="">Adopt a Cat</a></li>
<li class="last leaf"><a href="/en/virtual-adoption" title="">Virtual Adoption</a></li>
</ul><span class="drop-down-toggle"><span class="drop-down-arrow"></span></span></li>
<li class="expanded"><a href="/en/content/volunteer" title="Volunteer">Volunteer</a><ul class="menu"><li class="first leaf"><a href="/en/content/shelter">Shelter</a></li>
<li class="leaf"><a href="/en/content/volunteer-clinic">Volunteer at the Clinic</a></li>

 @media screen and (max-device-width: 440px) {

  .top_left, 
  .top_right,
  .search_block,
  .region-user-menu{ width: 100% !important; }

  #logo { text-align: center; width: 100%; }

  #site-title{ width: 100%; }

  #site-title a{ width: 100%; text-align: center; float:none; /* EMS */}

  .social-icons{ position: inherit; width: 100%; }

  .social-icons ul{ text-align: center; }

  .top_right .region-user-menu ul.menu{ float: none; }

  .block-menu ul{ float: none; text-align: center; }
}

看起来style="overflow: hidden; display: block;" 是由 js 文件添加的,它只出现在移动设备上。 我有一个被调用的 js 脚本:

    jQuery(document).ready(function($) {
  $('.nav-toggle').click(function() {
    $('#main-menu div ul:first-child').slideToggle(250);
    return false;
  });
  if( ($(window).width() > 640) || ($(document).width() > 640) ) {
      $('#main-menu li').mouseenter(function() {
        $(this).children('ul').css('display', 'none').stop(true, true).slideToggle(250).css('display', 'block').children('ul').css('display', 'none');
      });
      $('#main-menu li').mouseleave(function() {
        $(this).children('ul').stop(true, true).fadeOut(250).css('display', 'block');
      })
        } else {
    $('#main-menu li').each(function() {
      if($(this).children('ul').length)
        $(this).append('<span class="drop-down-toggle"><span class="drop-down-arrow"></span></span>');
    });
    $('.drop-down-toggle').click(function() {
      $(this).parent().children('ul').slideToggle(250);
    });
  }

});

这是导致问题的原因吗?我该如何适应它?

【问题讨论】:

    标签: css drupal responsive-design


    【解决方案1】:

    您使用的是旧的 jquery 版本“v1.5.2”。 显然在旧版本中有一个bug。 最好的解决方案是将版本更改为更新的版本。如果你不能这样做,那么修复你的 CSS 如下

    .menu{ overflow:visible!important; } 
    

    记得使用@media 仅将其添加到小屏幕

    另一种解决方案是通过 JS 执行与上述相同的操作。在下面添加一行

    $('.menu').attr("style","overflow:visible"); 
    

    紧接着

    $('#main-menu div ul:first-child').slideToggle(250);
    

    【讨论】:

    • 我认为 overflow:hidden 是由 javascript 添加的。它只出现在手机上。我已经编辑了上面的问题以显示 javascript。如何删除它?
    • 嗨 LTech 我在上面编辑了我的答案,希望它会有所帮助。
    猜你喜欢
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 2015-03-30
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多