从另一个 div 添加悬停触发器

发布于 2024-09-02 06:37:33 字数 299 浏览 4 评论 0原文

我正在尝试从另一个 div 激活一个 div 的本机悬停效果。我知道我可以在 jQuery 中完成这一切并在其中添加样式,但宁愿将本机 :hover 留在 CSS 中。我只是想知道是否有办法让它工作:

$("#div1").live("mouseenter", function() {
  $("#div2").trigger("mouseenter");
});

我想通过做这样的事情来调用它,但它不起作用。难道真的没有办法从另一个元素的事件触发一个事件吗?

提前致谢。

I am trying to activate the native hover effect of a div from another div. I understand that I could do this all in jQuery and add the styles in there, but would rather leave the native :hover in the CSS. I'm just wondering if there is a way for this to work:

$("#div1").live("mouseenter", function() {
  $("#div2").trigger("mouseenter");
});

I'd like to call it by doing something like this, but it isn't working. Is there really no way to trigger an event from another element's event?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无法回应 2024-09-09 06:37:33

我相信是的

$("#div1").live("mouseenter", function() {
  $("#div2").mouseenter();
});

I believe it is

$("#div1").live("mouseenter", function() {
  $("#div2").mouseenter();
});
云醉月微眠 2024-09-09 06:37:33

这应该有效吗?

$("#div1").mouseenter(function() {
  $("#div2").mouseenter();
});

This should work?

$("#div1").mouseenter(function() {
  $("#div2").mouseenter();
});
一百个冬季 2024-09-09 06:37:33

此处已回答此问题

根据 W3C 的规范,:hover
伪类只能被应用
用户发起操作时。

:hover 伪类适用于
用户指定一个元素(用
一些指点设备),但不
激活它。例如,视觉
用户代理可以应用这个
当光标(鼠标
指针)悬停在生成的框上
由元素。用户代理不
支持互动媒体不
必须支持这个伪类。

This have been answered here

according to the W3C's spec, the :hover
pseudo-class should only be applied
when the user initiates the action.

The :hover pseudo-class applies while
the user designates an element (with
some pointing device), but does not
activate it. For example, a visual
user agent could apply this
pseudo-class when the cursor (mouse
pointer) hovers over a box generated
by the element. User agents not
supporting interactive media do not
have to support this pseudo-class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文