Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
125 views

Random Background (JavaScript Animation)

This JavaScript script randomly selects background colors when a button is clicked. It uses 15 predetermined background colors and randomly chooses one. The script works in most modern browsers and inserts JavaScript code into the <HEAD> and <BODY> sections of an HTML page to randomly change the background color when a user clicks a link and display the new foreground and background colors.

Uploaded by

Amit Sony
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

Random Background (JavaScript Animation)

This JavaScript script randomly selects background colors when a button is clicked. It uses 15 predetermined background colors and randomly chooses one. The script works in most modern browsers and inserts JavaScript code into the <HEAD> and <BODY> sections of an HTML page to randomly change the background color when a user clicks a link and display the new foreground and background colors.

Uploaded by

Amit Sony
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Random Background

Get a random background color with the touch of a button. This JavaScript uses 15
pre-determined background colors and then randomly chooses one. This is a great
effect if you know what background colors don't interfere with the text on your
page. Then, you can make them the 15 pre-determined background colors.

This script will work in most recent browsers including FireFox

Insert into <HEAD>


<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function rnd(scale) {
var dd=new Date();
return((Math.round(Math.abs(Math.sin(dd.getTime()))*1000000000)%scale));
}
function show() {
document.blah.bg.value=document.bgColor;
document.blah.fg.value=document.fgColor;
}
document.fgColor=256*rnd(255)+16*rnd(255)+rnd(255);
document.bgColor=256*rnd(255)+16*rnd(255)+rnd(255);
// End -->
</SCRIPT>

Insert into <BODY>


<CENTER>
<a href="javascript:history.go(0)">Click here to get new colors</a>
</center>
<FORM name=blah>
<table border=0 width=100%><tr><td align=left>Foreground color</td>
<TD align=right>Background color</TD>
</TR>
<TR>
<TD align=left>
<input type=text name=fg>
</TD>
<TD align=right>
<input type=text name=bg>
</TD>
</TR>
</TABLE>
</FORM>
</CENTER>

You might also like