Javascript - Generate random dark color

前端 未结 4 1057
既然无缘
既然无缘 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:36

    Take any random digit from 0-5 as the first digit of your color and then choose the rest of the five digits using your above code.

    JS Fiddle: http://jsfiddle.net/xP5v8/

    var color,
           letters = '0123456789ABCDEF'.split('')
    function AddDigitToColor(limit)
    {
        color += letters[Math.round(Math.random() * limit )]
    }
    function GetRandomColor() {
        color = '#'
        AddDigitToColor(5)
        for (var i = 0; i < 5; i++) {
            AddDigitToColor(15)
        }
        return color
    }
    

提交回复
热议问题