[英]Trigger a delayed hover event with Jquery
I'm trying to trigger a delayed hover event: 我正在尝试触发延迟的悬停事件:
$(".graphic").delay(500).trigger('mouseover').trigger('mouseout');
But the delay is being ignored. 但是延迟被忽略了。
Any ideas? 有任何想法吗?
delay() only affects the animation queue, but trigger() is synchronous. delay()仅影响动画队列,但trigger()是同步的。 You can use queue() to schedule a function triggering the events after the delay:
您可以使用queue()来计划在延迟后触发事件的函数:
$(".graphic").delay(500).queue(function(next) {
$(this).trigger("mouseover").trigger("mouseout");
next();
});
The .delay()
method is best for delaying between queued jQuery effects . .delay()
方法最适合延迟排队的jQuery效果 。
To delay the initial effect, use setTimeout()
function. 要延迟初始效果,请使用
setTimeout()
函数。 By the way, you could use mouseover()
instead of trigger('mouseover')
顺便说一句,您可以使用
mouseover()
而不是trigger('mouseover')
setTimeout(function () {
$(".graphic").mouseover().mouseout();
}, 500);
The jQuery API says: jQuery API说:
Only subsequent events in a queue are delayed;
只有队列中的后续事件才会延迟; for example this will not delay the no-arguments forms of .show() or .hide() which do not use the effects queue.
例如,这不会延迟不使用效果队列的.show()或.hide()的无参数形式。
Maybe you can set a timer, that will trigger mouseover/out after 500 ms using Windows.setTimeout 也许你可以设置一个计时器,使用Windows.setTimeout在500毫秒后触发鼠标悬停/输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.