Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use jQuery trigger() with hoverIntent

Is it possible to trigger a hoverIntent on an element.

I have tried $(elem).trigger('hoverIntent');, which didn't work.

Edit: Js Fiddle: http://jsfiddle.net/H2p6T/

like image 259
smilly92 Avatar asked Jun 05 '26 08:06

smilly92


2 Answers

Simply triggering any of the event types did nothing unless the hoverIntent had been triggered genuinely.

I took a look at the hoverIntent source and it expects two things: mouseenter and mousemove with pointer coordinates defined. So I triggered events with fake coordinates:

$('.foo').trigger({ type:"mouseenter", pageX:"123", pageY:"123" });
$('.foo').trigger({ type:"mousemove", pageX:"123", pageY:"123" });

The coordinates don't matter as long as they are close enough to each other to trigger hoverIntent.

I used the r7 version for this.

like image 95
sihv Avatar answered Jun 07 '26 23:06

sihv


Have you tried

$(elem).trigger('hover');

or

$(elem).trigger('mouseover');
$(elem).trigger('mouseout');

or

$(elem).trigger('mouseenter');
$(elem).trigger('mouseleave');

hoverIntent is a plugin not an actual event so I believe you have to trigger an event that hoverIntent actually binds to your element

Here's an example of it working with the mouseenter/mouseleave

http://jsfiddle.net/H2p6T/3/

like image 23
wirey00 Avatar answered Jun 07 '26 22:06

wirey00



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!