我正在尝试触发延迟的悬停事件:
$(".graphic").delay(500).trigger('mouseover').trigger('mouseout');
但是延迟被忽略了。
有什么想法吗?
答案 0 :(得分:8)
delay()仅影响动画队列,但trigger()是同步的。您可以使用queue()来安排在延迟后触发事件的功能:
$(".graphic").delay(500).queue(function(next) {
$(this).trigger("mouseover").trigger("mouseout");
next();
});
答案 1 :(得分:2)
.delay()
方法最适合在排队的jQuery效果之间延迟 。
要延迟初始效果,请使用setTimeout()
功能。顺便说一下,您可以使用mouseover()
代替trigger('mouseover')
setTimeout(function () {
$(".graphic").mouseover().mouseout();
}, 500);
答案 2 :(得分:2)
仅延迟队列中的后续事件;例如,这不会延迟不使用效果队列的.show()或.hide()的无参数形式。
也许你可以设置一个计时器,使用Windows.setTimeout
在500毫秒后触发鼠标悬停/输出