随机获取颜色JS
2021-09-08 本文已影响0人
肥羊猪
function getRandomSafeColor() {
const base = ['00', '33', '66', '99', 'CC', 'FF']
const len = base.length
const bg = []
const random = Math.ceil(Math.random() * 215 + 1)
let res
for (let r = 0; r < len; r++) {
for (let g = 0; g < len; g++) {
for (let b = 0; b < len; b++) {
bg.push('#' + base[r].toString() + base[g].toString() + base[b].toString())
}
}
}
for (let i = 0; i < bg.length; i++) {
res = bg[random]
}
return res
}