jquery - 使用 jquery 更改 div 的背景

标签 jquery jquery-animate

我使用以下代码来更改背景颜色:

        $('.posts').animate({height: '100px', backgroundColor: '#0000FF'}, 2000);
        $('.posts a').animate({color: '#00FF00'}, 2000);

在 Firebug 上出现以下错误,而不是在页面中预览颜色变化:

Expected color but found 'NaNpx'. Error in parsing value for 'background-color'. Declaration dropped.
Expected color but found '#00FF00px'. Error in parsing value for 'color'. Declaration dropped.

我的代码有什么错误?

最佳答案

如果没有 jQuery UI,则无法使用 animate 来设置颜色动画。

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.)

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.

来源:http://api.jquery.com/animate/

关于jquery - 使用 jquery 更改 div 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6492418/

相关文章:

javascript - 每 4 个 div 换行 - 错误行为

Jquery PHP如何检查提交表单后复选框是否已被选中

jQuery 函数循环更改背景图像使 Firefox 崩溃

javascript - 在悬停和鼠标离开时对 div 进行动画处理并延迟

javascript - 将图像动画化到鼠标单击的位置

javascript - Jquery 弹出工具提示

javascript - 图像和 anchor 的 FancyBox 问题

javascript - 表单提交错误允许提交

jQuery 动画填充在 Chrome 中无法正常工作

javascript - 继续向左拉师