Use JavaScript to implement color background and text

Source: Internet
Author: User
Tags array implement return
Use JavaScript to implement color background and text

There are many kinds of JavaScript code for creating color backgrounds and text, but most background colors have a jump sense and are not soft enough. The effect of this example is particularly cool!

Please see the effect:



Background please use the bgcolor parameter, the foreground text please use the Fgcolor parameter.

all the code is as follows:

1. Background:

< HTML >
< head >
< title >bgcolor</title >
< meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
< script language= "JavaScript" >
<!--
Can assign the initial color of the background here
r=255;
g=50;
b=50;
flag=0;
T=new Array;
O=new Array;
D=new Array;

function Hex (a,c)
{
T[a]=math.floor (C/16)
O[a]=c%16
Switch (T[a])
{
Case 10:
T[a]= ' a ';
Break
Case 11:
t[a]= ' B ';
Break
Case 12:
t[a]= ' C ';
Break
Case 13:
t[a]= ' D ';
Break
Case 14:
t[a]= ' E ';
Break
Case 15:
t[a]= ' F ';
Break
Default
Break
}
Switch (O[a])
{
Case 10:
O[a]= ' a ';
Break
Case 11:
o[a]= ' B ';
Break
Case 12:
o[a]= ' C ';
Break
Case 13:
o[a]= ' D ';
Break
Case 14:
o[a]= ' E ';
Break
Case 15:
o[a]= ' F ';
Break
Default
Break
}
}

Function Ran (a,c)
{
if ((Math.random () >2/3| | c==0) &&c< 255)
{
C++
d[a]=2;
}
Else
{
if (Math.random () < =1/2| | c==255) &&c >0)
{
c--
D[a]=1;
}
else d[a]=0;
}
Return C
}
function Do_it (a,c)
{
if ((d[a]==2&&c< 255) | | | c==0)
{
C++
d[a]=2
}
Else
if ((d[a]==1&&c >0) | | c==255)
{
c--;
D[a]=1;
}
if (a==3)
{
if (d[1]==0&&d[2]==0&&d[3]==0)
Flag=1
}
Return C
}
function Disco ()
{
if (flag==0)
{
R=ran (1, R);
G=ran (2, g);
B=ran (3, B);
Hex (1,R)
Hex (2,G)
Hex (3,B)
Document.bgcolor= "#" +t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
Flag=50
}
Else
{
R=do_it (1, R)
G=do_it (2,G)
B=do_it (3,B)
Hex (1,R)
Hex (2,G)
Hex (3,B)
Document.bgcolor= "#" +t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
flag--
}
if (document.all)
SetTimeout (' Disco () ', 20)
}
-->
</script >

< body bgcolor= "#FFFFFF" text= "#000000" >
</body >
2, the foreground text:


< HTML >
< head >
< title >bgcolor</title >
< meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
< script language= "JavaScript" >
<!--
Can assign the initial color of the background here
r=255;
g=0;
b=0;
flag=0;
T=new Array;
O=new Array;
D=new Array;
function Hex (a,c)
{
T[a]=math.floor (C/16)
O[a]=c%16
Switch (T[a])
{
Case 10:
T[a]= ' a ';
Break
Case 11:
t[a]= ' B ';
Break
Case 12:
t[a]= ' C ';
Break
Case 13:
t[a]= ' D ';
Break
Case 14:
t[a]= ' E ';
Break
Case 15:
t[a]= ' F ';
Break
Default
Break
}
Switch (O[a])
{
Case 10:
O[a]= ' a ';
Break
Case 11:
o[a]= ' B ';
Break
Case 12:
o[a]= ' C ';
Break
Case 13:
o[a]= ' D ';
Break
Case 14:
o[a]= ' E ';
Break
Case 15:
o[a]= ' F ';
Break
Default
Break
}
}

Function Ran (a,c)
{
if ((Math.random () >2/3| | c==0) &&c< 255)
{
C++
d[a]=2;
}
Else
{
if (Math.random () < =1/2| | c==255) &&c >0)
{
c--
D[a]=1;
}
else d[a]=0;
}
Return C
}
function Do_it (a,c)
{
if ((d[a]==2&&c< 255) | | | c==0)
{
C++
d[a]=2
}
Else
if ((d[a]==1&&c >0) | | c==255)
{
c--;
D[a]=1;
}
if (a==3)
{
if (d[1]==0&&d[2]==0&&d[3]==0)
Flag=1
}
Return C
}
function Disco ()
{
if (flag==0)
{
R=ran (1, R);
G=ran (2, g);
B=ran (3, B);
Hex (1,R)
Hex (2,G)
Hex (3,B)
Document.fgcolor= "#" +t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
Flag=50
}
Else
{
R=do_it (1, R)
G=do_it (2,G)
B=do_it (3,B)
Hex (1,R)
Hex (2,G)
Hex (3,B)
Document.fgcolor= "#" +t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
flag--
}
if (document.all)
SetTimeout (' Disco () ', 0)
}
-->
</script >

< body text= "#000000" style= "font:25pt blackbody" > Sadie Network Computer Application
</body >


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.