这是我的代码。
在第4行,我想在鼠标输入lastItemsLink 2秒后运行this.openList。
我该怎么做?
lastItemsLink = $(".last-items"),
openLastItemsList = {
init: function() {
lastItemsLink.on("mouseenter", this.openList);
lastItemsLink.on("mouseleave", this.closeList);
},
openList: function() {
lastItemsContainer.stop(false, true).slideDown("fast");
},
closeList: function() {
lastItemsContainer.stop(false, true).fadeOut("fast");
}
};
答案 0 :(得分:2)
您可能需要执行类似
的操作lastItemsLink = $(".last-items"),
openLastItemsList = {
init: function () {
lastItemsLink.on("mouseenter", this.openList);
lastItemsLink.on("mouseleave", this.closeList);
},
openList: function () {
openLastItemsList.timer = setTimeout(function () {
lastItemsContainer.stop(false, true).slideDown("fast");
delete openLastItemsList.timer;
}, 2000)
},
closeList: function () {
if (openLastItemsList.timer) {
clearTimeout(openLastItemsList.timer)
} else {
lastItemsContainer.stop(false, true).fadeOut("fast");
}
}
};
演示:Fiddle
答案 1 :(得分:1)
使用setTimeout:
lastItemsLink.on("mouseenter", function () {
setTimeout(this.openList, 2000)
});
答案 2 :(得分:1)