我正在使用基于jQuery的下拉菜单,并希望为下拉动画添加延迟(slideDown)。我环顾四周看看如何实现setTimeout但无法让它与我的代码一起工作。有人可以帮忙吗?
这是我的代码:
$(document).ready(function() {
function megaHoverOver(){
$(this).find(".sub").slideDown(500);
}
function megaHoverOut(){
$(this).find(".sub").slideUp(150);
}
var config = {
sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
interval: 0, // number = milliseconds for onMouseOver polling interval
over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
timeout: 0, // number = milliseconds delay before onMouseOut
out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};
$("#mainnav-first li").hoverIntent(config);
});
顺便说一下,我尝试了以下但是没有用:
$(document).ready(function() {
setTimeout(function megaHoverOver(){
$(this).find(".sub").slideDown(500);
}, 500);
function megaHoverOut(){
$(this).find(".sub").slideUp(150);
}
var config = {
sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
interval: 0, // number = milliseconds for onMouseOver polling interval
over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
timeout: 0, // number = milliseconds delay before onMouseOut
out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};
$("#mainnav-first li").hoverIntent(config);
});
答案 0 :(得分:3)