使用 JQUERY 停止项目的悬停效果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5854071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:55:00  来源:igfitidea点击:

Stop Hover effect of an item using JQUERY

jquerycsshover

提问by thecodeparadox

I have some divelements and each of them have a hovereffect applied by CSS. But I don't always want this hover effect; it should only activate under specific conditions.

我有一些div元素,每个元素都有hoverCSS 应用的效果。但我并不总是想要这种悬停效果;它应该只在特定条件下激活。

Now, how can I disable those hovereffects using jQuery when my conditions are satisfied? What is the code for disabling hover? I don't have access to CSS files.

现在,hover当我的条件满足时,如何使用 jQuery禁用这些效果?禁用代码是hover什么?我无权访问 CSS 文件。

回答by Shadow Wizard is Ear For You

Just use the jQuery hoverinstead of the CSS one.

只需使用jQueryhover而不是 CSS 之一。

E.g. instead of such CSS:

例如,而不是这样的 CSS:

#Div1:hover { background-color: yellow; }

Have this jQuery:

有这个jQuery:

$("#Div1").hover(function() {
    $(this).css("background-color", "yellow");
}, function() {
    $(this).css("background-color", "");
});

Same effect, and you control the JS code and can have conditions.
Live test case: http://jsfiddle.net/THXuc/

效果一样,你控制JS代码,可以有条件。
现场测试用例:http: //jsfiddle.net/THXuc/

回答by Shakeeb Ahmed

you can do this by using

你可以通过使用做到这一点

<script>
$("someDiv").hover(function(event) {
//apply some conditions if yes
  event.preventDefault();
else
return true;
});
</script>

Hope this will work for you....

希望这对你有用......

Thanks

谢谢

回答by kaveman

You could apply a different class to the div(s) in question, using jquery .hover(). On mousein, apply the class and on mouseout, remove it.

您可以div使用 jquery将不同的类应用于有问题的(s).hover()。在 mousein 上,应用该类,在 mouseout 上,将其删除。