随机获取一种颜色值的三种方法
2016-11-16 10:12
309 查看
闲来无事,想起了初中时流行的山寨手机的跑马灯。于是想动手自己做一个。
那会的跑马灯都是红蓝两色居多,俗。
我这种二十一世纪的潮流人士肯定得做那种千百种颜色的。
姹紫嫣红,美哉。
这样做的话,颜色值就不能一个一个手写了,于是想做成不确定的颜色。
第一种写法:
function colorRandom() { var a, b, c; var a = parseInt(255 - Math.random() * 255).toString(16); var b = parseInt(255 - Math.random() * 255).toString(16); var c = parseInt(255 - Math.random() * 255).toString(16); colorStr = '#' + a + b + c; //alert(str) };
第二种写法:
function colorRandom() { colorStr = "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6); //alert(str) };
第三种写法:
function colorRandom() { colorStr = "#"+("00000"+(Math.random()*0x1000000<<0).toString(16)).slice(-6); //alert(str) };
对了,外边记得声明一个colorStr把颜色值存起来。
相关文章推荐
- java 获取随机数字的三种方法
- javascript获取随机rgb颜色和十六进制颜色的方法
- js jquery获取随机生成id的服务器控件的三种方法
- js生成随机颜色方法代码分享(三种)
- js jquery获取随机生成id的服务器控件的三种方法
- JS获取随机颜色(3种方法)
- AJAX从服务端获取数据的三种方法
- str=="" str.Length==0 str==String.Empty三种方法判断字符串为空,哪一种更快?
- Mysql中获取刚插入的自增长id的三种方法归纳
- Servlet的Web应用---三种方法获取表单的各种属性(源码)
- DOS命令下获取远程主机MAC地址的三种方法
- [译]获取系统网络MAC地址的三种方法
- 从Biztalk Tracking DataBase中编程获取Message的三种方法
- 获取网卡的三种方法(转)
- 实现 Table 的行交替颜色、选中行变色的一种方法。演示+源码
- AJAX从服务端获取数据的三种方法
- 获取Live Mail的一种方法?
- 随机获取博客的某篇随笔的方法
- AJAX从服务端获取数据的三种方法
- Mysql中获取刚插入的自增长id的三种方法归纳