我知道是否有可能用JS触发CSS悬停效果,而不需要使用额外的类...

下面是我想做的一个例子:

i have tried fireing the effect using mouseenter() but this does not trigger the CSS hover effect.

PS: I have made a function that helps a user using a online CMS. The help function shows you how to do stuff by moving a image around that shows you how to use stuff. The virtual cursor can click stuff, show elements etc.. But i would like this virtual cursor to tigger the :hover effects set in the CSS as well.

推荐答案

我知道你想做什么,但为什么不干脆这么做:

$('div').addClass('hover');

该类已在CSS中定义...

As for you original question, this has been asked before and it is not possible unfortunately. e.g. http://forum.jquery.com/topic/jquery-triggering-css-pseudo-selectors-like-hover

然而,如果您的样式表是用Javascript定义的,那么您想要的功能可能是可能的.见:

希望这有帮助!

Jquery相关问答推荐

为什么函数没有进入

使用jquery将外部代码插入div

在 jQuery 中,我想删除 div 中的所有 HTML

纯css关闭按钮

显示的 jQuery 日期 Select 器年份

页面滚动后,jQuery可拖动在错误的位置显示助手

未捕获的语法错误:无法在文档上执行querySelector

如何使用 Twitter Bootstrap 弹出框进行 jQuery 验证通知?

如何使用jQuery在弹出窗口中预览输入类型=文件中的选定图像?

在不丢失光标位置的情况下更新输入值

jQuery ajax (jsonp) 忽略超时并且不触发错误事件

使用 JQuery 激活 bootstrap 选项卡

类方法中的Typescript this

jQuery ajax 成功回调函数定义

!!~(不是波浪号/bang bang 波浪号)如何改变包含/包含数组方法调用的结果?

检测页面是否已完成加载

在 jquery 中使用 AJAX Post 从强类型 MVC3 视图传递模型的正确方法

jquery $(window).height() 正在返回文档高度

在 Javascript/jQuery 中,(e) 是什么意思?

小于 10 给数字加 0