Javascript - Generate random dark color

前端 未结 4 1055
既然无缘
既然无缘 2021-02-20 11:43

I have this method to generate me random colors for font:

function getRandomRolor() {
     var letters = \'0123456789ABCDEF\'.split(\'\');
     var color = \'#         


        
4条回答
  •  甜味超标
    2021-02-20 12:19

    As you know RGB at 0,0,0 is black the darkest and it goes toward getting light until (255,255,255) so you can stop it to go above 100, to get only dark colors or say 9 in hex:

    Here is jsFiddle

    function getDarkColor() {
        var color = '#';
        for (var i = 0; i < 6; i++) {
            color += Math.floor(Math.random() * 10);
        }
        return color;
    }
    

提交回复
热议问题