如何通过jquery以编程方式调用mouseenter事件 [英] How to invoke the mouseenter event programmatically via jquery

查看:94
本文介绍了如何通过jquery以编程方式调用mouseenter事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的html结构中,我有一个锚标记元素,附加了hoverIntent插件事件。

In my html structure I have one anchor tag element which has hoverIntent plugin event attached.

     $('a').hoverIntent(function(event){// some code to show popup;})

每当我手动悬停在锚标签上时,它会执行一些ajax调用并从服务中恢复数据并显示弹出窗口。

Whenever I hover on the anchor tag manually it does some ajax call and brings back the data from service and shows popup.

我想从代码中触发mouseenter / hover / mousemove(任何可以带来弹出窗口的东西)

I want to trigger the mouseenter/hover/mousemove (anything which can bring the popup) from code (without any manual action)

我尝试过基本的jquery函数,比如

I tried basic jquery functions like

   $('selector').trigger('hover') and
   $('selector').trigger('mouseenter')

但没有任何效果,这可以调用hover / mouseenter功能而不会中断用户吗?

But nothing worked, Is this possible to invoke the hover/mouseenter functionality without users interruption?

推荐答案

hoverIntent jQuery插件使用 mouseenter mousemove 事件来确定是否触发。如果您只是触发 mouseenter 事件,则不会发生任何事情。

The hoverIntent jQuery plugin uses both mouseenter and mousemove events to determine whether to fire or not. If you simply trigger the mouseenter event nothing will happen because of this.

您需要先拨打 mouseenter 事件并包含鼠标位置。然后你需要调用 mousemove 事件,也包括鼠标位置。

You'll need to first call the mouseenter event and include a mouse position. Then you need to call the mousemove event, also including the mouse position.

jsbin 显示了该示例。如果你悬停悬停我项目而没有先悬停绿色框,则没有任何反应。你是否将绿色框格式化为红色,之后悬停我链接将起作用。要以编程方式触发此操作而不先悬停绿色框,请使用以下调用:

This jsbin shows the example. If you hover the "Hover me" item without first hovering the green box, nothing happens. Is you hover the green box to make it red, the "hover me" link will work afterwards. To trigger this programmatically without first hovering the green box, use these calls:

var e = $.Event('mouseenter');
e.pageX = 50;
e.pageY = 50;
$("#testing").trigger(e);

var e2 = $.Event('mousemove');
e2.pageX = 50;
e2.pageY = 50;
$("#testing").trigger(e2);

这篇关于如何通过jquery以编程方式调用mouseenter事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆