In diesem Artikel Beispiel wird die Methode beschrieben, dass die Farben von Webhintergrund durch JS zufällig generiert werden. Teilen Sie es für Ihre Referenz. Die spezifische Implementierungsmethode lautet wie folgt:
Kopieren Sie den Code wie folgt: <html>
<kopf>
<titels> js Spezialeffekte zufällig generierte Webseiten Hintergrundfarbe </title>
<Styles>
.30pt {Schriftgröße: 30pt; Farbe:#DE3076}
</Style>
<Script Language = "JavaScript">
<!-
color = new Array ("0", "3", "6", "9", "c", "f");
Geschwindigkeit = 250;
document.bgcolor = "fffff";
BG = New Array ("ffffff", "ffffff", "ffffff");
Funktion begin () {
document.form.col1.Value = "x"; document.form.col2.Value = "x";
document.form.col3.Value = "x"; i = 0; rollen (Geschwindigkeit);
}
Funktionsroll (SpeedB) // Räder rollen
{
if (document.form.col1.value == "x") {
document.form.c1.value = document.form.b1.Value;
document.form.b1.value = document.form.a1.Value;
document.form.a1.Value =
Farbe [math.round (math.random ()*10)%6]+
Farbe [math.round (math.random ()*10)%6]; // Verwenden Sie zufällige Funktionen, um Farbwerte am Rad zu generieren
}
if (document.form.col2.Value == "x") {
document.form.c2.Value = document.form.b2.Value;
document.form.b2.Value = document.form.a2.Value;
document.form.a2.Value =
Farbe [math.round (math.random ()*10)%6]+
Farbe [math.round (math.random ()*10)%6];
}
if (document.form.col3.Value == "x") {
document.form.c3.Value = document.form.b3.Value;
document.form.b3.Value = document.form.a3.Value;
document.form.a3.Value =
Farbe [math.round (math.random ()*10)%6]+
Farbe [math.round (math.random ()*10)%6];
}
setTimeout ("roll ("+speedb+")", speedb);
}
Funktionsstopp (col) // Das Rad stoppt das Rollen
{
if (col == 1) {document.form.col1.Value = ""; i ++;}
if (col == 2) {document.form.col2.Value = ""; i ++;}
if (col == 3) {document.form.col3.Value = ""; i ++;}
if (i == 3) {
BG [0] = document.form.a1.Value+
document.form.a2.Value+
document.form.a3.Value;
BG [1] = document.form.b1.Value+
document.form.b2.Value+
document.form.b3.Value;
BG [2] = document.form.c1.Value+
document.form.c2.Value+
document.form.c3.Value;
SpeedB = 500000; Roll (SpeedB);
}
}
Funktionsansicht (Buchstabe) // Farbvorschau
{
document.bgcolor = BG [Buchstaben];
document.form.color.value = "#"+bg [letter];
}
->
</script>
</head>
<Center>
<br> <br> <br> <br>
<Formular name = "Form">
<Table CellPadding = 2 Grenze = 1>
<tr> <td align = center>
<Eingabe type = text name = "a1" size = 3 onfocus = "this.blur ()" value = "">
<Eingabe type = text name = "a2" size = 3 onfocus = "this.blur ()" value = "">
<Eingabe type = text name = "a3" size = 3 onfocus = "this.blur ()" value = "">
<Eingabetyp = Taste onclick = "Ansicht (0)" value = "preview"> <br>
<Eingabe type = text name = "b1" size = 3 onfocus = "this.blur ()" value = "">
<Eingabe type = text name = "b2" size = 3 onfocus = "this.blur ()" value = "">
<Eingabe type = text name = "b3" size = 3 onfocus = "this.blur ()" value = "">
<Eingabetyp = Taste onclick = "Ansicht (1)" value = "preview"> <br>
<Eingabe type = text name = "c1" size = 3 onfocus = "this.blur ()" value = "">
<Eingabe type = text name = "c2" size = 3 onfocus = "this.blur ()" value = "">
<Eingabe type = text name = "c3" size = 3 onfocus = "this.blur ()" value = "">
<Eingabetyp = Taste onclick = "Ansicht (2)" value = "preview"> <br>
<Eingabetyp = Taste onclick = "Stop (1)" value = "x" name = "col1">
<Eingabetyp = Taste onclick = "Stop (2)" value = "x" name = "col2">
<Eingabetyp = Taste onclick = "Stop (3)" value = "x" name = "col3">
</td>
<td Valign = Middle Align = Center>
<Eingabe type = button onclick = "begin ()" value = "start!"> <p>
<Tabelle bgcolor = fffff border = 1 cellspacing = 0>
<tr> <td align = center valign = Middle> Drücken Sie "x" und das Rad hört auf ... <p>
Bg color = <Eingabe type = text size = 7 value = "#ffffff" name = color>
</td> </tr>
</table>
</td> </tr>
</table>
</form>
</center>
<Tabellenklasse = 30pt>
<tr> <td> Zufällige Farbgenerierung
</tr> <tr> <td> Drücken
</tr> <tr> <td> Drücken Sie die drei x -Tasten, um den Farbwert festzulegen
</tr> <tr> <td> Drücken Sie die Vorschau -Taste, um den Farbton -Effekt anzuzeigen
</tr>
</table> <p>
</Body>
</Html>
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.