设为首页收藏本站

IT技术擎 - 最棒的IT web技术交流社区

 找回密码
 注册为IT技术擎人

QQ登录

只需一步,快速开始

搜索
热搜: php h5 jquery
查看: 15|回复: 0

[javascript] js生成随机颜色

[复制链接]
发表于 2018-8-10 19:50:19 | 显示全部楼层 |阅读模式
  1. [/code]
  2. [code]
  3. var shine=0.8;
复制代码
  1. <br>vararrays = ['[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]'];
  2. functionrandomColor(random,size){if(size==2){if(shine <1){ a--;if(a==0){ shine=parseFloat(shine)+0.2; } arrays=['[255,182,193,'+shine+']','[144,238,144,'+shine+']','[255,235,205,'+shine+']','[240,128,128,'+shine+']','[255,186,0,'+shine+']','[255,225,189,'+shine+']','[227,229,241,'+shine+']','[248,228,239,'+shine+']','[223,237,224,'+shine+']','[249,236,191,'+shine+']']; } }
  3. elseif(size==3){if(shine >0.2){ a--;if(a==0){ shine=(shine-0.2).toFixed(1); } arrays=['[255,182,193,'+shine+']','[144,238,144,'+shine+']','[255,235,205,'+shine+']','[240,128,128,'+shine+']','[255,186,0,'+shine+']','[255,225,189,'+shine+']','[227,229,241,'+shine+']','[248,228,239,'+shine+']','[223,237,224,'+shine+']','[249,236,191,'+shine+']']; } };//var arrays = ['[123,104,238,0.5]','[0,255,255,0.5]','[0,250,154,0.5]','[0,255,0,0.5]','[255,255,0,0.5]','[255,165,0,0.5]','[178,34,34,0.5]','[148,0,211,0.5]','[255,250,205,0.5]','[255,215,0,0.5]']; //var r = Math.floor(Math.random()*256); //var g = Math.floor(Math.random()*256); //var b = Math.floor(Math.random()*256); returnarrays[random];//"["+r+","+g+","+b+", 0.7]";
  4. }
复制代码



上一篇:学员优秀博文赏析:双基准快速排序实现
下一篇:promise顺序执行,返回结果存放在数组
该用户未在地球留下任何的痕迹

本版积分规则

QQ|小黑屋|帮助|IT技术擎 ( 沪ICP备15054863号  

GMT+8, 2018-8-22 15:51

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表