JQuery添加延迟slideUp mouseleave
我将添加一个延迟来滑动我的下拉菜单。如果我离开子菜单链接,它将在2秒后滑动。目前它可以立即滑动。问题是如果你让下拉菜单关闭 ****更新(18.4.2014/18:40):** **这个版本不起作用。男人们快速靠近(看这里:) 在伦诺克斯的回答中:dropdownmenü保持开放()**** 守则:JQuery添加延迟slideUp mouseleave,jquery,menu,delay,mouseleave,Jquery,Menu,Delay,Mouseleave,我将添加一个延迟来滑动我的下拉菜单。如果我离开子菜单链接,它将在2秒后滑动。目前它可以立即滑动。问题是如果你让下拉菜单关闭 ****更新(18.4.2014/18:40):** **这个版本不起作用。男人们快速靠近(看这里:) 在伦诺克斯的回答中:dropdownmenü保持开放()**** 守则: if ($(window).width() > 962) { $("ul#menu li ul li:has(ul)").find("a:first").addClass("activ
if ($(window).width() > 962) {
$("ul#menu li ul li:has(ul)").find("a:first").addClass("active");
$("ul#menu li").hover(function() {
$(this).addClass("hover");
$('ul:first', this).css('visibility', 'visible');
$(this).children('ul').delay(20).slideDown(300); // speed of the slide
}, function() {
$(this).removeClass("hover");
$('ul:first', this).css('visibility', 'hidden');
$(this).children('ul').delay(20).slideUp(200); // speed of the slide
});
}
两秒等于2000(毫秒)。At:Lennox:All Dropdownmenüs保持开放
if ($(window).width() > 962) {
var slideupTimeout = undefined;
$("ul#menu li ul li:has(ul)").find("a:first").addClass("active");
$("ul#menu li").hover(function() {
// If they re-enter, cancel the slideUp
if (typeof slideupTimeout == "number") {
clearTimeout(slideupTimeout);
slideupTimeout = undefined;
}
$(this).addClass("hover");
$('ul:first', this).css('visibility', 'visible');
$(this).children('ul').delay(20).slideDown(300); // speed of the slide
}, function() {
var that = this;
// Cancel if present, don't want to leak these.
if (typeof slideupTimeout == "number") {
clearTimeout(slideupTimeout);
slideupTimeout = undefined;
}
// In 2 seconds, call slideUp
slideupTimeout = setTimeout(function() {
$(that).removeClass("hover");
$('ul:first', that).css('visibility', 'hidden');
$(that).children('ul').delay(20).slideUp(200); // speed of the slide
// Be sure we're always managing this ID properly. We don't want
// it to linger and accidentally cancel an unrelated timer!
slideupTimeout = undefined;
}, 2000)
});
}