简体   繁体   English

jQuery,fadeToggle和list-items

[英]jQuery, fadeToggle, and list-items

OK, so. 好的,所以。 I'm trying to create a dropdown menu of sorts using fadeToggle(). 我正在尝试使用fadeToggle()创建各种类型的下拉菜单。

http://westrock.juggernautwebsites.com/ is where the site is currently located. http://westrock.juggernautwebsites.com/是该网站目前所在的位置。

As you can see, when a user selects 'Properties', the fadeToggle occurs. 如您所见,当用户选择“属性”时,会出现fadeToggle。 However, after the dropdown occurs, and a user wants to select a li from the properties dropdown, they are unable to (I know I have return false; set, but that was supposed to be for the original ul, no?) 然而,在下拉发生之后,并且用户想要从属性下拉列表中选择li,他们无法(我知道我已经返回false;设置,但那应该是原始ul,不是吗?)

As well, when the child items are displaying, if you hover over About, the :hover effect displays on the Properties child li. 同样,当显示子项时,如果将鼠标悬停在“关于”上,则:“悬停”效果将显示在“属性”子项li上。

I'm boggled. 我很难过。 Any help, greatly appreciated. 任何帮助,非常感谢。

$('#menu-item-13').click(function() {
    $(this).children('ul').fadeToggle({
        duration: 200
    });
    return false;
});

*EDIT I feel like I need to restrict the css and jQuery from affecting children list-items and a, but I don't know how to do this. *编辑我觉得我需要限制css和jQuery影响子列表项和a,但我不知道如何做到这一点。 I thought children only went one level down the DOM, and since I selected 'ul', the function wouldn't affect list-items... 我认为孩子们只在DOM下了一级,因为我选择了'ul',这个函数不会影响列表项...

Your example doesn't work at all for me, but if I'm understanding you correctly, you want the child ul to not be affected by the click handler attached to the parent. 您的示例对我来说根本不起作用,但如果我正确理解您,您希望子ul不受附加到父级的单击处理程序的影响。 You can do this: 你可以这样做:

$('#menu-item-13 > ul').click(function(e){
   e.stopPropagation();

   // ... do your thing
});

This basically stops the click on the ul from bubbling up to the parent #menu-item-13 . 这基本上停止了点击ul从冒泡到父#menu-item-13 Because of this, the fadeToggle will also not trigger from the click on the ul, so if that is still needed you will have to add it to the ul 's click. 因此, fadeToggle也不会因点击ul而触发,所以如果仍然需要,你必须将它添加到ul的点击中。

Thanks for everyone's help! 谢谢大家的帮助! Here's what I eventually ended up using. 这是我最终使用的内容。

$('#primary li').hover(function() {
    $(this).children('ul').fadeToggle({
        duration: 200
    });
});
    $('menu-item-54').click(function() {
    return false;
});

What I was trying to accomplish upon hover (or click), the subnav would expand open. 我在悬停(或点击)时试图完成的任务,subnav将展开。

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

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