萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> Html5 >> html下雨效果代碼解析

html下雨效果代碼解析

這是一個HTML畫布上呈現刮風下雨的效果。您可以更改背景、畫布元素的寬度、高度。非常容易定制(許多水滴,風力,方向)。我們為大家收集整理了關於html下雨效果代碼,以方便大家參考。

<html>

<head>

<title>下雨效果的網頁背景</title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<body>

<script language="JavaScript">

<!--

var no = 50;

var speed = 1;

var ns4up = (document.layers) ? 1 : 0;

var ie4up = (document.all) ? 1 : 0;

var s, x, y, sn, cs;

var a, r, cx, cy;

var i, doc_width = 800, doc_height = 600;

if (ns4up) {

doc_width = self.innerWidth;

doc_height = self.innerHeight;

}

else

if (ie4up) {

doc_width = document.body.clientWidth;

doc_height = document.body.clientHeight;

}

x = new Array();

y = new Array();

r = new Array();

cx = new Array();

cy = new Array();

s = 8;

for (i = 0; i < no; ++ i) {

initRain();

if (ns4up) {

if (i == 0) {

document.write("<layer name="dot"+ i +"" left="1" ");

document.write("top="1" visibility="show"><font color="red">");

document.write(",</font></layer>");

}

else {

document.write("<layer name="dot"+ i +"" left="1" ");

document.write("top="1" visibility="show"><font color="red">");

document.write(",</font></layer>");

}

}

else

if (ie4up) {

if (i == 0) {

document.write("<div id="dot"+ i +"" style="POSITION: ");

document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");

document.write("visible; TOP: 15px; LEFT: 15px;"><font color="red">");

document.write(",</font></div>");

}

else {

document.write("<div id="dot"+ i +"" style="POSITION: ");

document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");

document.write("visible; TOP: 15px; LEFT: 15px;"><font color="red">");

document.write(",</font></div>");

}

}

}

function initRain() {

a = 6;

r[i] = 1;

sn = Math.sin(a);

cs = Math.cos(a);

cx[i] = Math.random() * doc_width + 1;

cy[i] = Math.random() * doc_height + 1;

x[i] = r[i] * sn + cx[i];

y[i] = cy[i];

}

function makeRain() {

r[i] = 1;

cx[i] = Math.random() * doc_width + 1;

cy[i] = 1;

x[i] = r[i] * sn + cx[i];

y[i] = r[i] * cs + cy[i];

}

function updateRain() {

r[i] += s;

x[i] = r[i] * sn + cx[i];

y[i] = r[i] * cs + cy[i];

}

function raindropNS() {

for (i = 0; i < no; ++ i) {

updateRain();

if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {

makeRain();

doc_width = self.innerWidth;

doc_height = self.innerHeight;

}

document.layers["dot"+i].top = y[i];

document.layers["dot"+i].left = x[i];

}

setTimeout("raindropNS()", speed);

}

function raindropIE() {

for (i = 0; i < no; ++ i) {

updateRain();

if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {

makeRain();

doc_width = document.body.clientWidth;

doc_height = document.body.clientHeight;

}

document.all["dot"+i].style.pixelTop = y[i];

document.all["dot"+i].style.pixelLeft = x[i];

}

setTimeout("raindropIE()", speed);

}

if (ns4up) {

raindropNS();

}

else

if (ie4up) {

raindropIE();

}

-->

</script>

<center>

<table>

<tr><td align=center>這雨下得真大呀!</td></tr>

</table>

</center>

<SCRIPT LANGUAGE="JavaScript">

<!-- hide

function goHist(a)

{

history.go(a);

}

//-->

</script>

<SCRIPT language=VBScript>

dim c,numgc

c=-100000

numgc=document.body.sourceIndex

sub SF

c=c+2

Document.all(numgc).style.BackgroundPosition="0 "&c

id=SetTimeOut("SF",64,"VBScript")

end sub

SF

</SCRIPT>

</body>

</html>

希望大家可以學會html下雨效果代碼.想了解更多精彩內容,請關注我們的網站!

相關推薦:

html禮花背景代碼分析 

想了解更多關於html語言,請點擊精品學習網編程開發欄目!! 

copyright © 萬盛學電腦網 all rights reserved