旋转单词js - 如何改变颜色

时间:2013-02-11 14:33:34

标签: jquery rotation words

我刚刚在另一个帖子中找到了这个演示,但是想问一下我是否有机会改变旋转文本的颜色,我正在玩弄但是无法弄明白,任何请帮助

工作demo

var keywords = ["awesome", "cool", "fantastic", "incredible"];
var count = 1;
setInterval(function(){    
    $("span.keyword").fadeOut(400, function(){        
        $(this).html(keywords[count]);        
        count++;        
        if(count == keywords.length)            
            count = 0;        
        $(this).fadeIn(400);    
    });
}, 2000);

2 个答案:

答案 0 :(得分:1)

只需使用其他数组来保存颜色,然后使用.css()

应用它们

这是一个有效的版本......

http://jsfiddle.net/zqEmT/11/

var keywords = ["awesome", "cool", "fantastic", "incredible"];
var colours = ["red", "green", "blue", "orange"];
var count = 1;
setInterval(function(){    
    $("span.keyword").fadeOut(400, function(){        
        $(this).html(keywords[count]).css("color", colours[count]);
        count++;        
        if(count == keywords.length)            
            count = 0;        
        $(this).fadeIn(400);    
    });
}, 2000);

答案 1 :(得分:0)

试试这个,它应该让你开始:

http://jsfiddle.net/zqEmT/9/

var keywords = ["awesome", "cool", "fantastic", "incredible"];
var count = 1;
setInterval(function(){    
    $("span.keyword").fadeOut(400, function(){        
        $(this).html(keywords[count]);        
        count++;        
        if(count == keywords.length)            
            count = 0;        

        var hue = 'rgb('
            + (Math.floor(Math.random() * 256)) + ','
            + (Math.floor(Math.random() * 256)) + ','
            + (Math.floor(Math.random() * 256)) + ')';        

        $(this).fadeIn(400).css('color', hue);    
    });
}, 2000);