每秒更改CSS颜色 [英] Changing the css color every second
本文介绍了每秒更改CSS颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何实现一个简单的动画效果的颜色每秒变化,如果有一个方式动画的动画,它可以更好
我刚刚尝试过:
.box')。delay(1000).css(background,red);
并且它不工作(延迟功能不工作).. anyways i需要类似两个:
$('。box')。delay(1000).css(background红);
$('。box')。delay(1000).css(background,green);
这样它变成红色 - >等待一秒,变成绿色 - >再次变红。 / p>
有可能吗?感谢!
解决方案
$(document).ready(function(){
setInterval(function(){
$('body')。animate({backgroundColor:'red'},300)
.animate({backgroundColor:'green'},300);
},1000);
});
http: //jsfiddle.net/theSifter/yR6jc/
Possible Duplicate:
How to loop a css background image with Jquery every few seconds?
I'm wondering how to achieve a simple "animation" effect of colors changing every second and if there is a way to animate the animation it can be even better.
I have just tried something like:
$('.box').delay(1000).css("background","red");
And it doesn't work at all (the delay function isn't working).. anyways i need like two of them:
$('.box').delay(1000).css("background","red");
$('.box').delay(1000).css("background","green");
So that it becomes red -> wait a second and becomes green -> becomes red again..
Is it possible? thanks!
解决方案
$(document).ready(function() {
setInterval(function() {
$('body').animate( { backgroundColor: 'red' }, 300)
.animate( { backgroundColor: 'green' }, 300);
}, 1000);
});
http://jsfiddle.net/theSifter/yR6jc/
这篇关于每秒更改CSS颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文