Use jQuery trigger() with hoverIntent

若如初见. 提交于 2019-12-05 21:31:03

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!