查看完整版本: 网页中加入下雨的效果

heking520 2008-1-11 02:55

网页中加入下雨的效果

把如下代码加入到<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=\"#999999\">");
document.write(",</font></layer>");
}
else {
document.write("<layer name=\"dot"+ i +"\" left=\"1\" ");
document.write("top=\"1\" visibility=\"show\"><font color=\"#999999\">");
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=\"#999999\">");
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=\"#999999\">");
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>

cottoneyes 2008-1-18 11:11

再次狂顶~~~好东东!

chihi 2008-1-18 11:15

让联合国安理会决定译成宇宙语由中国神州六号升空不断播放看有没有外星人的好帖?

Ease 2008-1-18 11:18

坐沙发,和楼主好好谈谈

nownow 2008-1-18 11:23

好帖一定要顶!!!

linthorxiao 2008-1-18 11:29

人生自古谁无死,哪个好贴不用顶!

Lossic 2008-1-18 11:32

顶贴要做到,不抛弃,不放弃!!

bigbigsmile 2008-2-15 12:34

萨达姆看了都要顶的贴,你还不顶??

bigblue 2008-2-28 21:51

一人顶贴,全家光荣!!

bigblue 2008-2-28 21:51

一人顶贴,全家光荣!!

bigblue 2008-3-3 16:43

一人顶贴,全家光荣!!

bigblue 2008-3-4 12:14

一人顶贴,全家光荣!!

bigblue 2008-3-5 12:30

一人顶贴,全家光荣!!

bigblue 2008-3-6 20:11

一人顶贴,全家光荣!!

bigblue 2008-3-6 20:11

一人顶贴,全家光荣!!

bigblue 2008-3-7 16:39

一人顶贴,全家光荣!!

Bigteeth 2008-3-8 15:05

猪年顶了无数贴,鼠年又来继续顶!!

zoeyi 2008-3-15 08:46

不错,值得顶!!

zoezy 2008-3-16 09:33

就得顶这样的帖子嘛~~呵呵~~

zoezy 2008-3-17 08:37

就得顶这样的帖子嘛~~呵呵~~

zoezy 2008-3-18 11:36

我终于……找到可以顶贴的地方了

zolatemur 2008-3-19 12:54

我和你还没分出高下!我还要再顶一次!!!

zolatemur 2008-3-20 09:14

总有一天,我会聚集一群伙伴,成为世界第一的千斤顶!

panda--故事继续 2008-3-21 11:24

回帖的那位,我的偶像。

panda..love 2008-3-25 11:37

楼主找了多久啊...

panda..love 2008-3-25 11:38

楼主找了多久啊...

panda..love 2008-3-25 11:44

感谢楼主替我们解决了不知批谁的问题

shlwch 2008-3-26 06:03

做爱做的事,顶好顶的贴!

shmily 2008-3-27 12:37

我不是一个随便顶贴的人,不过楼主的帖子我还是要顶的

shoelace 2008-3-28 09:19

子在川上曰:“有贴多好!”

shoelace 2008-3-29 14:06

子在川上曰:“有贴多好!”

爱的代价 2008-3-29 16:55

嗯,现在正在做网站呢,呵呵,就想在页面添加点特效上去了,谢谢楼主的分享哈

shoelace 2008-3-30 12:20

子在川上曰:“有贴多好!”

shoelace 2008-3-31 11:59

子在川上曰:“有贴多好!”
页: [1]
查看完整版本: 网页中加入下雨的效果
5.12四川大地震