I'm trying to trigger a delayed hover event:
$(".graphic").delay(500).trigger('mouseover').trigger('mouseout');
But the delay is being ignored.
Any ideas?
jQuery hover() MethodThe hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.
Is hover deprecated in jQuery? Deprecated in jQuery 1.8, removed in 1.9: The name “hover” used as a shorthand for the string “mouseenter mouseleave” .
jQuery mouseover() MethodThe mouseover() method triggers the mouseover event, or attaches a function to run when a mouseover event occurs. Note: Unlike the mouseenter event, the mouseover event triggers if a mouse pointer enters any child elements as well as the selected element.
delay() only affects the animation queue, but trigger() is synchronous. You can use queue() to schedule a function triggering the events after the delay:
$(".graphic").delay(500).queue(function(next) {
$(this).trigger("mouseover").trigger("mouseout");
next();
});
The .delay()
method is best for delaying between queued jQuery effects.
To delay the initial effect, use setTimeout()
function. By the way, you could use mouseover()
instead of trigger('mouseover')
setTimeout(function () {
$(".graphic").mouseover().mouseout();
}, 500);
The jQuery API says:
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.
Maybe you can set a timer, that will trigger mouseover/out after 500 ms using Windows.setTimeout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With