Use jQuery trigger() with hoverIntent

两盒软妹~` 提交于 2019-12-22 10:48:25

问题


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/


回答1:


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/




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/11839740/use-jquery-trigger-with-hoverintent

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