jQuery从给定列表中获取随机颜色
我想为我拥有的fadeIn/Out文本函数的文本设置随机颜色 功能(工作原理): 假设我想要颜色: 蓝色:#37fff5 绿色:#8cff04 橙色:#ffa018 热粉色:#f247f8 虽然我知道如何将颜色添加到给定元素中,但我不知道如何从上面列出的Solor中选择随机颜色: 要更改正在淡入的文本的颜色,我将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
//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)];
}