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

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

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

姹紫嫣红,美哉。

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

 

第一种写法:

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

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2020-04-14
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2021-11-27
  • 2021-08-21
相关资源
相似解决方案