随机生成颜色逐字打印 js

立即领取

最高 ¥2000 红包 限量领取

云服务器、主机等产品通用,可叠加官网常规优惠使用 | 限时领取

<!doctype html>
<html>
<head>
<title>颜色变幻的欢迎词</title>
</head>
<body onLoad=”loadText()”>
<Script language=”JavaScript”>
var someText = “美肤堂欢迎您,请多多指教!”;
var aChar;
var aSentence;
var i=0;
var cHex = new Array(“0″,”1″,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″,”A”,”B”,”C”,”D”,”E”,”F”);
var aColor;

function loadText()
{
for(k=0;k<6;k++){
var a = cHex[Math.floor(Math.random()*16)];
aColor += a;
console.log(a);}
//console.log(aColor);
// aColor = colors[Math.floor(Math.random()*cHex.length)];
aChar = someText.charAt(i);
if (i == 0)
aSentence = aChar;
else
{ aSentence = “”;
for(j=0;j<i;j++)
aSentence +=”&nbsp;&nbsp;&nbsp;”
aSentence += aChar; }
if (i < 50) i++;
if(i<=someText.length){
if (document.all)
{
textDiv.innerHTML= “<font color=’#”+aColor+”‘ face=’Tahoma’ size=’7′><i>”+aSentence+”</i>”;
setTimeout(“loadText()”,500);
}
else if (document.layers)
{
document.textDiv.document.write(“<font color=’#”+aColor+”‘ face=’Tahoma’ size=’5′><i>”+aSentence+”</i>”);
document.textDiv.document.close();
setTimeout(“loadText()”,500);
}
else if (document.getElementById)
{
document.getElementById(“textDiv”).innerHTML = “<font color=’#”+aColor+”‘ face=’Tahoma’size=’5’><i>”+aSentence+”</i>”;
setTimeout(“loadText()”,500);
}
}
else
{
if (document.all)
{
textDiv.innerHTML= “<font color=’#”+aColor+”‘ face=’Tahoma’ size=’7′><i>”+someText+”</i>”;
setTimeout(“loadText()”,500);
}
else if (document.layers)
{
document.textDiv.document.write(“<font color=’#”+aColor+”‘ face=’Tahoma’ size=’5′><i>”+someText+”</i>”);
document.textDiv.document.close();
setTimeout(“loadText()”,500);
}
else if (document.getElementById)
{
document.getElementById(“textDiv”).innerHTML = “<font color=’#”+aColor+”‘ face=’Tahoma’size=’5’><i>”+someText+”</i>”;
setTimeout(“loadText()”,500);
}
}
}
</SCRIPT>
<div id=”textDiv”></div>
</body>

未经允许不得转载:王刚博客 » 随机生成颜色逐字打印 js

赞 (3) 打赏

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏