2010-08-30 107 views
1

我正在寻找背景颜色的动画,以便在无限循环中循环varios预定义颜色。jquery,背景颜色转换循环

我不是一个程序员和新的jQuery的,如果有人可以帮助我弄清楚了这一点,我真的很感激IST

THX!

+0

你可以发布你已经做了什么吗?很难说你需要什么。 – Iznogood 2010-08-30 00:41:46

回答

2

window.setInterval('functionToChangeColour()',5000);这将每5000毫秒运行一次你的函数,按照你希望改变的方式改变颜色。你可以指定一个对象var obj = setInterval('functionToChangeColour()',5000);你可以指定一个对象var obj = setInterval('functionToChangeColour()',5000);到后来,如果你清除间隔喜欢使用window.clearInterval(OBJ)

2

建立在拜伦的解决方案,并利用该color animations plugin的:

// The array of colours and current index within the colour array 
// This array can be hex values or named colours 
var colours = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']; 
var currIndex = 0; 

// The element to animage the background-color of 
var elem = $('#element-id'); 

// Infinitely animate the background-color of your element every second 
var loop = setInterval(function(){ 
    elem.animate({backgroundColor: colours[currIndex++]}); 

    // Set the current index in the colour array, making sure to loop 
    // back to beginning once last colour is reached 
    currIndex = currIndex == colours.length ? 0 : currIndex; 
}, 1000); 

你可以看到它in action here