【问题标题】:Rotating words js - how to change the color as well旋转单词js - 如何改变颜色以及
【发布时间】:2013-02-11 14:33:34
【问题描述】:

我刚刚在另一个线程中找到了这个演示,但想问一下我是否有机会改变旋转文本的颜色,我正在玩,但无法弄清楚,任何帮助将不胜感激

工作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);

【问题讨论】:

    标签: jquery rotation words


    【解决方案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);
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2019-08-17
        • 1970-01-01
        • 2023-04-02
        • 2017-03-25
        • 2013-06-03
        • 2017-01-30
        • 2015-11-07
        • 2018-02-14
        相关资源
        最近更新 更多