标签:jquery javascript
我创建了一个可折叠的菜单,其结构如下:
>家长
>父母2
>家长3
>子类别
我有以下javascript
var config = {
over: function() { $(this).children('ul').slideDown('slow'); },
timeout: 5,
out: function() { }
}
$("ul.root-tags li").hoverIntent(config);
$('ul.root-tags').mouseout(function() {
$(this).children('li ul').each(function () {
$(this).slideUp('slow');
});
});
基本上我想在父项的悬停时打开子类别,但只在整个列表的mouseout上折叠打开的子类别,而不仅仅是父项.我目前的代码不会这样做.我需要做出哪些改变?
jsfiddle在这里http://jsfiddle.net/zkhVC/4/
解决方法:
这应该解决你的要求:
$('#head').mouseleave(function() {
$(this).find('li ul').each(function () {
$(this).stop().slideUp('slow');
});
});
$("ul li").mouseenter(function() {
$(this).children('ul').stop().slideDown('slow');
});
小提琴
说明
>不要使用悬停事件,因为它会一遍又一遍地被解雇你在元素上.您想要使用mouseenter.
>使用mouseleave而不是mouseout:
The
mouseleave
event differs frommouseout
in the way it handles event
bubbling. Ifmouseout
were used in this example, then when the mouse
pointer moved out of the Inner element, the handler would be
triggered. This is usually undesirable behavior. Themouseleave
event,
on the other hand, only triggers its handler when the mouse leaves the
element it is bound to, not a descendant. So in this example, the
handler is triggered when the mouse leaves the Outer element, but not
the Inner element.
>深入了解选择器的工作原理:这里不需要子功能.
>您希望在调用动画之前使用stop函数以防止动画缓冲.
标签:jquery,javascript 来源: https://codeday.me/bug/20190620/1247347.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。