简体   繁体   English

无法单击下拉菜单中的菜单链接

[英]Can't click on menu links in drop down menu

I'm working on a wordpress site with a mobile dropdown menu. 我正在使用移动下拉菜单在wordpress网站上工作。 The dropdown works fine but clicking on any link in the dropdown menu just closes the menu and doesn't go to the link. 下拉菜单可以正常工作,但是单击下拉菜单中的任何链接只会关闭菜单,并且不会转到该链接。

I can't find the JS code for this functionality so is there any code I can add to make sure clicking on any menu item within the menu div won't close the menu? 我找不到用于此功能的JS代码,因此可以添加任何代码来确保单击菜单div中的任何菜单项不会关闭菜单吗?

Below is the html. 下面是html。 Here's the site: www.nomad8.com 这是网站:www.nomad8.com

  <header class="edgtf-mobile-header">
    <div class="edgtf-mobile-header-inner">
                <div class="edgtf-mobile-header-holder">
            <div class="edgtf-grid">
                <div class="edgtf-vertical-align-containers">
                                            <div class="edgtf-mobile-menu-opener">
                            <a href="javascript:void(0)">
                    <span class="edgtf-mobile-opener-icon-holder">
                        <i class="edgtf-icon-font-awesome fa fa-bars " ></i>                    </span>
                            </a>
                        </div>

                    </div>
                </div> 
            </div>
        </div>

<nav class="edgtf-mobile-nav">
    <div class="edgtf-grid">
        <ul id="menu-production-1" class=""><li id="mobile-menu-item-5597" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home edgtf-active-item"><a href="http://mysite/about" class=" current "><span>menuiteams</span></a></li></span></a></li>
</ul>    
</div>
</nav>

    </div>
</header>

UPDATE: 更新:

I've added this code to the header and it kind of works. 我已经将此代码添加到标题中,并且可以正常工作。 But the anchor tags don't work all the time. 但是锚标记并非一直有效。 Only on the first click: 仅在第一次点击时:

(function($) {
$(document).ready(function(){
    $(".edgtf-mobile-menu-opener").click(function(){
    $('.edgtf-mobile-nav').fadeToggle(300);
 $('.edgtf-mobile-nav').css("display", "block");
 $('.edgtf-mobile-nav').css("height", "100px !important");

        e.stopPropagation();

});

      $(".edgtf-mobile-nav .edgtf-grid").click(function(e){

                    e.stopPropagation();

});
         $('.edgtf-mobile-nav > li').click(function(){


   $('.edgtf-mobile-nav').fadeIn('fast');
        });

});
})(jQuery); 

I wish i could inspect your code in chrome broswer. 我希望我可以在Chrome浏览器中检查您的代码。 That would have helped to determine the menu list wrapper/container . 那将有助于确定菜单列表包装器/容器

But i am guessing that your wrapper is edgtf-mobile-menu-opener 但是我猜你的包装是edgtf-mobile-menu-opener

However, you can target the wrapper that contains mobile menu list and the do something like this: 但是,您可以定位包含移动菜单列表的包装器,并执行以下操作:

$(document).ready(function(){
    $(".edgtf-mobile-menu-opener").click(function(){
    $('.edgtf-mobile-nav').fadeToggle(2000)
});

fadeToggle will fade the menu in and it will stay until you click the menu-icon again fadeToggle将淡入菜单,并且将保持不变 ,直到再次单击菜单图标

Just try that first and lets see 先尝试一下,看看

Well, clear the cache. 好吧,清除缓存。

However, i would like to know where you added the script to in your wp theme because you can be adding it wrongly. 但是,我想知道您在wp主题中将脚本添加到的位置,因为您可能会错误地添加它。

Add this to the CSS. 将此添加到CSS。 It's an issue with the theme framework itself it looks like. 它看起来像是主题框架本身的问题。 I had this issue myself and this worked as a fix. 我自己遇到了这个问题,并且可以解决此问题。

.dropdown-backdrop{
position: static;
}

That is most probably because you toggle (open/close) the navigation whenever you click on .edgtf-mobile-header . 这很可能是因为,只要您单击.edgtf-mobile-header就可以切换(打开/关闭)导航。

Try to change the toggle selector to .edgtf-mobile-opener-icon-holder . 尝试将切换选择器更改为.edgtf-mobile-opener-icon-holder

Thanks to @Dayo-Greats answer I managed to work this out..kind of. 感谢@ Dayo-Greats的回答,我设法解决了。

Here's the code that makes things work. 这是使事情正常运行的代码。 But for some reason #anchortag menu links still don't work. 但是由于某些原因,#anchortag菜单链接仍然无法使用。 Otherwise the links are now clickable. 否则,链接现在可以单击。 Any reason wy the anchor tags wouldn't work? 锚标签无法正常工作的原因是什么?

Here's my code: 这是我的代码:

(function($) {
$(document).ready(function(){
    $(".edgtf-mobile-menu-opener").click(function(){
    $('.edgtf-mobile-nav').fadeToggle(300);
 $('.edgtf-mobile-nav').css("display", "block");
 $('.edgtf-mobile-nav').css("height", "100px !important");

                    e.stopPropagation();
 // return;
});

      $(".edgtf-mobile-nav .edgtf-grid").click(function(e){

                    e.stopPropagation();
 // return;
});
});
})(jQuery); 

I don't have a privilege to make a comment yet. 我还没有发表评论的特权。

However, you did not pass the function argument( function() ) before you called e.stopPropagation(); 但是,在调用e.stopPropagation()之前,您没有传递函数arguments( function() ); as seen below: 如下图所示:

  (function($) {
    $(document).ready(function(){
     ....
    e.stopPropagation();

Quickly fix a bug in the your new code like this function(e) 快速修复新代码中的错误(例如函数)

  (function($) {
    $(document).ready(function(e){
     ....
     e.stopPropagation();

Try it again and lets see 再试一次,让我们看看

At the same time, i am thinking you can use another approach that shows the menu again, even when you clicked on the menu li element like this: 同时,我想您可以使用另一种方法再次显示菜单,即使您单击菜单li元素时也是如此:

....

  $(".edgtf-mobile-menu-opener").click(function(){
  $('.edgtf-mobile-nav').fadeToggle('slow', function(){

   #-> trying to target ul>li 
   $('.edgtf-mobile-nav > li').click(function(){

   #-> and when clicked ('.edgtf-mobile-nav > li') then show menu again
   $('.edgtf-mobile-nav').fadeIn('fast');
        })

...just thinking anyway ...只是反正思考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM