随机颜色生成


随机生成颜色

/*
 *随机颜色(十六进制代码) 
 */
function randomHexColor() {
    var seed = Math.random(), result = seed.toString(16).substr(2, 6);

    while (result.length < 6) {
        result += '0'
    }
    return '#' + result;
}

/*
 *随机颜色(RGB值)
 */
function randomRgbColor() {
    var rgb = [
        Math.floor(Math.random() * 255 + 1)
        , Math.floor(Math.random() * 255 + 1)
        , Math.floor(Math.random() * 255 + 1)
    ];

    return 'rgb(' + rgb.join(',') + ')';
}

 

posted @ 2024-01-10 16:24  DreamerSix  阅读(12)  评论(0编辑  收藏  举报