zoukankan      html  css  js  c++  java
  • 随机获取一种颜色值的三种方法

    闲来无事,想起了初中时流行的山寨手机的跑马灯。于是想动手自己做一个。

    那会的跑马灯都是红蓝两色居多,俗。

    我这种二十一世纪的潮流人士肯定得做那种千百种颜色的。

    姹紫嫣红,美哉。

    这样做的话,颜色值就不能一个一个手写了,于是想做成不确定的颜色。

    第一种写法:

    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把颜色值存起来。

  • 相关阅读:
    Codeforces #548 (Div2)
    Codeforces #550 (Div3)
    UVA
    ios 动画
    CAAnimation
    iOS三种定时器的用法NSTimer、CADisplayLink、GCD
    iOS使用宏写单例
    iOS完美的网络状态判断工具
    iOS开发
    iOS自定义控件教程:制作一个可重用的旋钮
  • 原文地址:https://www.cnblogs.com/ricoliu/p/6068419.html
Copyright © 2011-2022 走看看