jquery动画: change span color not working

标签 jquery jquery-animate

我有一个跨度类:cash_warn。我想用jquery动画改变span的颜色,但是它不起作用。

我现在拥有的:

$('.cash_warn').animate({ color: "#ff8484" }, 500);

另一方面,这确实可以正常工作,但它不会为其设置动画:

$('.cash_warn').css('color',"#ff8484");

html:

<div class=" friends-shadow detailreward3 detailreward"  style="position:absolute;
 height:71px;  width:238px; left: 453px; top: 40px; padding:20px; z-index:99; font:
 bold 11px Helvetica, Arial, sans-serif;">

<span style=" color:#fff" class="cash_warn">
text
</span>

<br /> <br />

 more text
</div>

知道出了什么问题吗?

最佳答案

除非使用 jQuery color 插件,否则无法设置颜色动画。 (GitHub)

All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used). Property values are treated as a number of pixels unless otherwise specified.

Source

Note: The jQuery UI project extends the .animate() method by allowing some non-numeric styles such as colors to be animated. The project also includes mechanisms for specifying animations through CSS classes rather than individual attributes.

关于jquery动画: change span color not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10567259/

相关文章:

jQuery 滚动以在 div 上同时淡入淡出和动画

javascript - JQuery - 将 div 动画化为鼠标坐标

javascript - 我如何知道用户是否单击了 "back"按钮?

javascript - 下拉弹跳问题

javascript - 多个滑动div的时间和速度

jquery - 使用slideup、向下滑动下拉菜单的jquery效果

JQuery 停止任何其他事件和函数,直到此事件完成

javascript - jQuery 在 .each 循环中获取输入值

javascript - 为什么我的 jQuery 脚本只执行一次?

jquery - 默认子div打开onClick