用jQuery触发悬停? [英] Trigger hover with jQuery?

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

问题描述

  $(#a)。parent()。trigger('hover') 

用jQuery?该代码不适合我。

解决方案

正如TJ Crowder和Endel指出的,这不能直接完成。但是,您可以通过添加类来实现应用了悬停样式的 span 的效果。



首先,改变你的CSS,看起来像这样:

  #text:hover,#text.hovered 
{
/ *您的风格。 * /
}

这意味着相同的样式将被应用于文本,当它被徘徊时,以及它有类悬停时。然后,只要您想要悬停影响就添加类:

  $(#a)。parent()。 addClass( '盘旋'); 

当您不再需要时,请将其删除:

  $(#a)。parent()。removeClass('hovered'); 


How do I achive this

$("#a").parent().trigger('hover')

with jQuery? The code is not working for me.

解决方案

As pointed out by TJ Crowder and Endel, this can not be done directly. However, you can achieve the effect of the span having the hover style applied to it by adding a class.

First, change your CSS so it looks like this:

#text:hover, #text.hovered
{
    /* Your styles. */
}

That means that the same styles will be applied to text when it is hovered and when it has the class hovered. Then just add the class whenever you want to have the hover affect:

$("#a").parent().addClass('hovered');

And remove it when you no longer want it:

$("#a").parent().removeClass('hovered');

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

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