在jquery中创建循环背景动画
我想要的是:
当页面加载时 – 背景在10秒后变为红色,bgColor变为绿色,淡出淡出动画…再过10秒后变为橙色……然后再变为红色等等。
能有人帮忙吗
使用setinterval和更改背景的回调:
$("document").ready(function() { var colours = [ "blue", "orange", "pink" ]; var counter = 0; function cycleBackground() { $("body").animate({ backgroundColor: colours[counter] }, 500 ); counter++; if(counter == colours.length) { counter = 0; } } setInterval(cycleBackground, 10000); });
如果要在颜色之间平滑循环,则需要使用jQuery UI的动画function。