Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery从给定列表中获取随机颜色_Jquery_Random - Fatal编程技术网

jQuery从给定列表中获取随机颜色

jQuery从给定列表中获取随机颜色,jquery,random,Jquery,Random,我想为我拥有的fadeIn/Out文本函数的文本设置随机颜色 功能(工作原理): 假设我想要颜色: 蓝色:#37fff5 绿色:#8cff04 橙色:#ffa018 热粉色:#f247f8 虽然我知道如何将颜色添加到给定元素中,但我不知道如何从上面列出的Solor中选择随机颜色: 要更改正在淡入的文本的颜色,我将 //show first item jQuery("div.custom_logo").children().eq(currentItem).css('color', theRando

我想为我拥有的fadeIn/Out文本函数的文本设置随机颜色

功能(工作原理):

假设我想要颜色:

蓝色:#37fff5 绿色:#8cff04 橙色:#ffa018 热粉色:#f247f8

虽然我知道如何将颜色添加到给定元素中,但我不知道如何从上面列出的Solor中选择随机颜色:

要更改正在淡入的文本的颜色,我将

//show first item
jQuery("div.custom_logo").children().eq(currentItem).css('color', theRandomColor).fadeIn(initialFadeIn);


谢谢你,

我认为这种方式最好

RandomColor = function () {
    var _colors = ["#aaa", "#bbb", "#ccc", "red", "white"];
    this.getRandomColor = function() {
        var rnd = Math.floor(Math.random()*_colors .length);
        return _colors[rnd];
    }
};

(new RandomColor()).getRandomColor();
RandomColor = function() {
    colors = ['red', 'white', 'blue', 'green']
    return colors[Math.floor(Math.random()*colors.length)];
}
函数的返回将是颜色 例如:

a=随机颜色();
console.log(a)/“blue”

将颜色放入一个数组中,并使用Math.random选择一种颜色。这是一篇关于从数学中获取整数的简洁的小文章。你最近一直在写Java还是什么?这也可能是一个简单的函数;
RandomColor = function () {
    var _colors = ["#aaa", "#bbb", "#ccc", "red", "white"];
    this.getRandomColor = function() {
        var rnd = Math.floor(Math.random()*_colors .length);
        return _colors[rnd];
    }
};

(new RandomColor()).getRandomColor();
RandomColor = function() {
    colors = ['red', 'white', 'blue', 'green']
    return colors[Math.floor(Math.random()*colors.length)];
}