js 随机颜色

74 阅读1分钟
export function getRandomColor() {
    const color =
    '#' +
    '0123456789abcdef'
        .split('')
        .map(function (v, i, a) {
            return i > 5 ? null : a[Math.floor(Math.random() * 16)];
        })
        .join('');
    return color;
}
export function getRandomLightColor() {
    const arr = [
        'pink',
        'red',
        'orange',
        'green',
        'cyan',
        'blue',
        'purple',
        'yellow',
        'geekblue',
        'magenta',
        'volcano',
        'gold',
        'lime'
    ];
    return arr[Math.floor(Math.random() * arr.length)];
}