问题描述
我一直在尝试在Chrome中找到代码来模拟 mouseover
,但即使mouseover侦听器被触发,CSShover声明从未设置!
I've been trying to find code to simulate mouseover
in Chrome but even though the "mouseover" listener gets fired, the CSS "hover" declaration is never set!
我也尝试过:
//Called within mouseover listener
theElement.classList.add("hover");
但是没有什么可以将元素更改为 hover
声明。
But nothing seems to change the element to what is declared in its hover
declaration.
这是否可能?
推荐答案
p>你不能。这不是。
You can't. It's not a trusted event.
大多数不受信任的事件不应触发默认操作,但click或DOMActivate事件除外。
Most untrusted events should not trigger default actions, with the exception of click or DOMActivate events.
您必须手动添加一个类并在mouseover / mouseout事件上添加/删除。
You have to add a class and add/remove that on the mouseover/mouseout events manually.
这篇关于如何在纯JavaScript中模拟鼠标悬停,以激活CSS“:hover”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!