【发布时间】:2012-09-15 09:34:30
【问题描述】:
好的,就是这样。
简单地说,我希望能够通过 CSS 淡出身体的背景,并经常改变,然后循环。
有什么想法可以用 CSS 和 jQuery 实现吗?
谢谢!
【问题讨论】:
标签: javascript jquery css background document-body
好的,就是这样。
简单地说,我希望能够通过 CSS 淡出身体的背景,并经常改变,然后循环。
有什么想法可以用 CSS 和 jQuery 实现吗?
谢谢!
【问题讨论】:
标签: javascript jquery css background document-body
您可以使用 jquery animate 方法,并在它完成时使用新颜色再次调用该方法:
var color = ["red","green","blue"];
var i = 0;
function changeColor()
{
// Change to the next color over 2 seconds. When it is done, call this method again.
$("body").animate({"background-color":color[i]}, 2000, changeColor);
i++; // Increment the counter so the next color in the array is shown
i = i % 3; // Make sure i is never greater than 2 by using the modulous.
}
changeColor();
看到这个小提琴:http://jsfiddle.net/johnkoer/vDCSw/5/
【讨论】: