简体   繁体   English

仅限子元素上的jQuery slideDown()

[英]jQuery slideDown() on child elements only

forgive me in advance, I ride the javascript short bus :( 请原谅我,我乘坐javascript短巴士:(

I have the following code for a slideDown() / slideUp() with jQuery on a primary navigation: 我在主导航上有以下带有jQuery的slideDown() / slideUp()代码:

//jQuery slideDown for menu dropdowns
$('.menu').addClass('js-enabled')

$('.js-enabled li').hoverIntent(function () {
   $(".sub-menu").slideDown('slow');
 }, 
 function () {
   $(".sub-menu").slideUp('slow');
});

My problem is that the code is not unique to the .sub-menu 's which are children of a given <li> ... Can someone tell me how to make the above code specific to the <li> element being hovered according to the original $('.js-enabled li').hoverIntent target? 我的问题是代码不是给定<li>子代的.sub-menu独有的。有人可以告诉我如何使上面的代码特定于要悬停的<li>元素。原始的$('.js-enabled li').hoverIntent目标?

* EDIT : Here is the production site, demonstrating the bug where all ".sub-menu"'s are being animated by the effect: http://valeriaentertainment.com.s66112.gridserver.com/ * * 编辑:这是生产站点,演示了通过效果使所有“ .sub-menu”动画化的错误: http : //valeriaentertainment.com.s66112.gridserver.com/ *

I assume inside the handler you can reference the current element with this . 我假设可以在处理程序内部使用this引用当前元素。 Then you can use .find() to search for certain descendants: 然后,您可以使用.find()搜索某些后代:

$(this).find(".sub-menu").slideDown('slow');

You can pass the current <li> element as the context argument of the $() function: 您可以将当前<li>元素作为$()函数的context参数传递:

$(".js-enabled li").hoverIntent(function() {
   $(".sub-menu", this).slideDown("slow");
}, function() {
   $(".sub-menu", this).slideUp("slow");
});

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

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