美文网首页
随机获取颜色JS

随机获取颜色JS

作者: 肥羊猪 | 来源:发表于2021-09-08 17:14 被阅读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
        }
    

    相关文章

      网友评论

          本文标题:随机获取颜色JS

          本文链接:https://www.haomeiwen.com/subject/wouabltx.html