添加和删除带有动画的类 [英] Add and remove a class with animation
问题描述
我编写了一个脚本,用于在另一个框的悬停处更改框的颜色: http://jsfiddle.net/w5b9v/2/
I have written a script that changes the box's color in another box's hover: http://jsfiddle.net/w5b9v/2/
如何在此过渡中添加动画? 预先感谢
How can I add animation to this transition? Thanks in advance
推荐答案
jQuery .animate方法主要为数字属性设置动画,并且不包括添加减法类.
The jQuery .animate method animates mostly numeric properties and doesn't cover adding a subtracting a class.
如果只想更改不透明度,则可以使用 .fadeTo .
If you simply want to change opacity, you can use .fadeTo.
$(".wrapper div").not(this).fadeTo('slow', 0.5);
以上内容将使不透明度降低一半.
The above will reduce the opacity by half.
此问题提供了更多信息,包括jQueryUI switchClass 方法.该问题还建议使用 .animateToSelector 插件.
This question provides more information, including the jQueryUI switchClass method. That question also suggests the .animateToSelector plugin.
最后有 animateToClass ,但这似乎只是包装了功能将.animate转换为类,这意味着您的某些非数字值将不起作用.
Finally there is animateToClass, but that appears to simply wrap the features of .animate into a class, which means some of your non-numeric values won't work.
这篇关于添加和删除带有动画的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!