我有这段代码:
var shortcuts = $('#geo_shortcuts');
shortcuts.find('li').hoverIntent(
function () {
// Open the Panel
$(this).find('.geo_shortcuts_content').stop().animate({
top: '-122'
}, 300);
},
function () {
//Close de Panel
$(this).find('.geo_shortcuts_content').stop().animate({
top: '0'
}, 400);
}
);
如何在鼠标输出2秒后才允许关闭面板?我知道我应该做一个settimeout函数,但我不知道如何。
答案 0 :(得分:1)
尝试使用delay()
方法:
$(this).find('.geo_shortcuts_content').stop().delay(2000).animate({
top: '0'
}, 400);
答案 1 :(得分:0)
您可以使用计时器来执行此操作
hideDelayTimer = null;
shortcuts.find('li').hoverIntent(
function () {
// Open the Panel
clearTimeout(hideDelayTimer);
$(this).find('.geo_shortcuts_content').stop().animate({
top: '-122'
}, 300);
},
function () {
//Close de Panel
clearTimeout(hideDelayTimer);
hideDelayTimer = setTimeout(function () {
hideDelayTimer = null;
$(this).find('.geo_shortcuts_content').stop().animate({
top: '0'
}, 400);
}, 2000);
度过愉快的一天