The first line of your function does a .fadeIn()
and waits until that's finished before setting the .html()
on the next line. So the second time it fades in while the html content is still the final word. Just combine the first two lines to look more like the other lines and it will work:
function wordfade() {
$('#msg').fadeIn(2000).html("Sustainable").css("color", "#3AE44E").delay(800).fadeOut(2000, function () {
$('#msg').fadeIn(2000).html("Eye Catching").css("color", "#F18D0B").delay(800).fadeOut(2000, function () {
// etc.
Demo: http://jsfiddle.net/PNDg4/
And then consider rewriting the whole thing to avoid so many nested callbacks:
var words = [
{ word : "Sustainable", color : "#3AE44E" },
{ word : "Eye Catching", color : "#F18D0B" },
{ word : "Modern Design", color : "#0B8DF1" },
{ word : "Energy Efficient", color : "#AD0BF1" },
/* etc */],
current = -1;
function wordfade() {
current = (current + 1) % words.length;
$("#msg").html(words[current].word)
.css("color", words[current].color)
.fadeIn(2000)
.delay(800)
.fadeOut(2000, wordfade);
}
wordfade();