.hover上的jQuery slideDown菜单在第二次悬停之前不起作用 [英] jQuery slideDown menu on .hover doesn't work until 2nd hover
问题描述
以下代码成功运行,但菜单slideDown仅在我的菜单项上方的第二个悬停上有效.第一次立即出现,就像第一次没有应用jQuery一样.
The following code works successfully, except the menu slideDown only works on the second hover over my menu item. The first time it appears instantly, like no jQuery is applied at all the first time around.
$(document).ready( function() {
// animate dropdown menus
$('#wp-admin-bar ul li').hover(
function () {
//show submenu
$('ul', this).slideDown(180);
},
function () {
//hide submenu
$('ul', this).slideUp(180);
}
);
});
奇怪的是,如果我添加
$(this).addClass("hover");
该类立即添加-在第一个悬停时.
The class is added immediately - on the the first hover.
我对此有些困惑.
推荐答案
好,方程中的$(this).addClass("hover");
在哪里?因为听起来好像正在发生的事情是,第一个mouseIn通过CSS显示了div,然后通过jQuery代码从头开始进行显示.除非使用元素的style
属性设置了display
,否则隐藏和显示的动画将不起作用.
Ok where does: $(this).addClass("hover");
come into the equation? Because it sounds like what is happening is that the first mouseIn is showing the div via CSS and then its ok from ther eon out with the jQuery code. Animations that hide and show dont work unless display
is set with the style
attribute of the element.
这篇关于.hover上的jQuery slideDown菜单在第二次悬停之前不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!