Rumah  >  Artikel  >  hujung hadapan web  >  js如何生成随机的颜色(代码示例)

js如何生成随机的颜色(代码示例)

不言
不言asal
2018-08-11 10:05:582194semak imbas

本篇文章给大家带来的内容是关于js如何生成随机的颜色(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

var shine=0.8;

var arrays = ['[255,182,193,0.8]','[144,238,144,0.8]','[255,235,205,0.8]','[240,128,128,0.8]','[255,186,0,0.8]','[255,225,189,0.8]','[227,229,241,0.8]','[248,228,239,0.8]','[223,237,224,0.8]','[249,236,191,0.8]'];
function randomColor(random,size){
    if(size==2){
        if(shine<1){
          a--;
          if(a==0){
              shine=parseFloat(shine)+0.2;    
              
          }
          arrays=[&#39;[255,182,193,&#39;+shine+&#39;]&#39;,&#39;[144,238,144,&#39;+shine+&#39;]&#39;,&#39;[255,235,205,&#39;+shine+&#39;]&#39;,&#39;[240,128,128,&#39;+shine+&#39;]&#39;,&#39;[255,186,0,&#39;+shine+&#39;]&#39;,&#39;[255,225,189,&#39;+shine+&#39;]&#39;,&#39;[227,229,241,&#39;+shine+&#39;]&#39;,&#39;[248,228,239,&#39;+shine+&#39;]&#39;,&#39;[223,237,224,&#39;+shine+&#39;]&#39;,&#39;[249,236,191,&#39;+shine+&#39;]&#39;];
        }
    }else if(size==3){
        if(shine>0.2){
             a--;
             if(a==0){
                 shine=(shine-0.2).toFixed(1);
             }
             arrays=[&#39;[255,182,193,&#39;+shine+&#39;]&#39;,&#39;[144,238,144,&#39;+shine+&#39;]&#39;,&#39;[255,235,205,&#39;+shine+&#39;]&#39;,&#39;[240,128,128,&#39;+shine+&#39;]&#39;,&#39;[255,186,0,&#39;+shine+&#39;]&#39;,&#39;[255,225,189,&#39;+shine+&#39;]&#39;,&#39;[227,229,241,&#39;+shine+&#39;]&#39;,&#39;[248,228,239,&#39;+shine+&#39;]&#39;,&#39;[223,237,224,&#39;+shine+&#39;]&#39;,&#39;[249,236,191,&#39;+shine+&#39;]&#39;];
            
        }
        
    };
    //var arrays = [&#39;[123,104,238,0.5]&#39;,&#39;[0,255,255,0.5]&#39;,&#39;[0,250,154,0.5]&#39;,&#39;[0,255,0,0.5]&#39;,&#39;[255,255,0,0.5]&#39;,&#39;[255,165,0,0.5]&#39;,&#39;[178,34,34,0.5]&#39;,&#39;[148,0,211,0.5]&#39;,&#39;[255,250,205,0.5]&#39;,&#39;[255,215,0,0.5]&#39;];
    //var r = Math.floor(Math.random()*256);
    //var g = Math.floor(Math.random()*256);
    //var b = Math.floor(Math.random()*256);
    return arrays[random];//"["+r+","+g+","+b+", 0.7]";
}

相关推荐:

php实现万年历的完整代码

php如何生成HTML文件的类?php生成html文件类的方法

Atas ialah kandungan terperinci js如何生成随机的颜色(代码示例). Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn