
1 color
2 0到16
3 0到f
4 #ff0000
5 红
6 null
7 desX
8 desY
9 ondblclick
10 intervalId
写得辛苦
给点分吧
//将背景色的值定义成空字符串
var bgColor="";
//循环6次,生成一个随机的六位数
for (var i = 0 ; i < 6 ; i++)
{
bgColor += "" + Mathround(Mathrandom() 9);
}
//将随机生成的背景颜色值赋给页面的背景色。
documentgetElementById("test")
stylebackgroundColor="#" + bgColor;
把下面的代码放在一个空网页的最后体验一下。
<SCRIPT language=javascript type=text/javascript>
var a=Mathround(Mathrandom()0x1000000);
var c="00000"concat(atoString(16));
documentbgColor="#"+csubstr(clength-6,6);
</SCRIPT>
调用的例子:
consolelog(ColorLuminance(colorRGB(),05)); //先自动生成16进制颜色,在转成比原有颜色轻50%;
//16进制随机颜色
function colorRGB(){
return '#' + (function (h) {
return new Array(7 - hlength)join("0") + h
})((Mathrandom() 0x1000000 << 0)toString(16))
}
ColorLuminance接受两个参数:
参数1: 十六进制颜色值,例如“#abc”或“#123456”(散列是可选的)
参数2: 亮度因数,即,-01是10%更暗,02是轻20%等。
function ColorLuminance(hex, lum) {
// validate hex string
hex = String(hex)replace(/[^0-9a-f]/gi, '');
if (hexlength < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hexsubstr(i2,2), 16);
c = Mathround(Mathmin(Mathmax(0, c + (c lum)), 255))toString(16);
rgb += ("00"+c)substr(clength);
}
return rgb;
}
相关资源:>
这是因为在css中,颜色的写法有三种,分别为:
颜色名称(比如:red,yellow,white 等等),
RGB方式(比如:rgb(255,255,255) 代表白色),
十六进制方式:(比如:#ffffff 代表白色)
你这个随机的是RGB的值,要包含在rgb()的括号里面,所以前面要拼接上rgb
以上就是关于求一道Javascript的推断题答案全部的内容,包括:求一道Javascript的推断题答案、用java如何随机生成颜色、js动态生成颜色浅的16进制值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)