【发布时间】:2010-11-30 06:25:00
【问题描述】:
我正在开发一个 jQuery 下拉菜单,当您将鼠标悬停在顶级项目上时它会淡入。我想设置它,以便当您将鼠标移开时,菜单不会立即消失。我有这个代码:
$(document).ready(function(){
$('ul#menu > li').hover(
// mouseover
function(){
$(this).find('>ul').fadeIn('fast');
},
// mouseout
function(){
setTimeout( function(){
alert('fadeout');
$(this).find('>ul').fadeOut('fast')
}, 1000 );
}
);
});
一秒钟后出现警报,但菜单并未淡出。
【问题讨论】:
-
我只是在想,这可能是因为“this”指向了
setTimeout函数中的其他东西吗? -
是的,没错。你得到了窗口。
-
你可以使用
.children('ul')而不是.find('>ul')顺便说一句。
标签: jquery menu hover delay settimeout