使用JS触发css悬停 [英] Trigger css hover with JS

查看:124
本文介绍了使用JS触发css悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道是否有可能以某种方式用JS触发CSS HOVER效果,而不必使用额外的类......

I would know if it is possible somehow to trigger the CSS HOVER effect with JS, without having to use a additional class...

这是一个例子我想做什么:
http://jsfiddle.net/pXbMZ/2/

Here is an example of what i want to do: http://jsfiddle.net/pXbMZ/2/

我尝试使用 mouseenter()来触发效果,但这不会触发CSS悬停效果。

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

PS:我已经创建了一个帮助用户使用在线CMS的功能。帮助功能向您展示如何通过移动图像来显示如何使用东西。虚拟光标可以点击东西,显示元素等。但是我希望这个虚拟光标能够触发:在CSS中设置的悬停效果。

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.

推荐答案

我知道你要做什么,但为什么不这么做呢:

I know what you're trying to do, but why not simply do this:

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

该类已在您的CSS中定义...

The class is already defined in your CSS...

至于你原来的问题,这个问题以前曾被问过,不幸的是不可能。
,例如 http://forum.jquery.com/topic/jquery -triggering-css-pseudo-selectors-like-hover

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,则可以使用所需的功能。请参阅:
http:// www.4pmp.com/2009/11/dynamic-css-pseudo-class-styles-with-jquery/

However, your desired functionality may be possible if your Stylesheet is defined is Javascript. see: http://www.4pmp.com/2009/11/dynamic-css-pseudo-class-styles-with-jquery/

希望这会有所帮助!

这篇关于使用JS触发css悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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