質問

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/

役に立ちましたか?

解決

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/

他のヒント

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.

Can you do it like this?

$(elem).hoverIntent();

Ok that didn't work...

I had a play with it: http://jsfiddle.net/8CCTM/11/

hoverIntent will trigger on mousenter() but it will only do it after the hoverIntent element has been activated with the mouse.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top