2010-08-30 15 views
1

Je cherche à animer la couleur d'arrière-plan afin qu'elle fasse défiler des couleurs prédéfinies varios dans une boucle sans fin.Jquery, boucle de transition de couleur d'arrière-plan

Je ne suis pas un programmeur et nouveau pour jquery, si quelqu'un pouvait me aider ceci j'apprécierais vraiment ist

thx!

+0

Pourriez-vous poster ce que vous avez déjà fait? Difficile de dire ce dont vous avez besoin précisément. – Iznogood

Répondre

2

window.setInterval ('functionToChangeColour()', 5000); Votre fonction fonctionnera toutes les 5000 millisecondes en changeant la couleur comme vous le souhaitez.

Vous pouvez affecter un objet var obj = setInterval ('functionToChangeColour()', 5000); à plus tard alors effacer l'intervalle si vous aimez en utilisant window.clearInterval (obj)

2

Miser sur la solution et faisant usage de la color animations plugin Byron:

// 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); 

Vous pouvez voir in action here.