我使用以下代码来更改背景颜色:
$('.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.
关于jquery - 使用 jquery 更改 div 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6492418/