代码为:
var no = 8 ;
var oTime = new Date();
var lastTime = oTime.getTime();
var x_sin, x_point, y_point;
var x_length, x_increased, y_increased;
var i, body_width = 932, body_height = 538;
var lastTime = 0;
var fallInterval = 2.4;x_sin = new Array();
x_point = new Array();
y_point = new Array();
x_length = new Array();
x_increased = new Array();
y_increased = new Array();
var oBody = document.body;
var d=document;/*body_width = oBody.clientWidth;
body_height = oBody.clientHeight;*/for (i = 0; i < no; ++ i) {
snowFlakeImgNo = Math.round(Math.random()*(snowflake.length-1));
x_sin[i] = 0;
x_point[i] = Math.random()*(body_width-250)+100;
y_point[i] = Math.random()*body_height;
x_length[i] = Math.random()*20;
// x_increased[i] = 0.02 + Math.random()/10;
// y_increased[i] = 0.7 + Math.random();
x_increased[i] = 0.08 + Math.random()/5;
y_increased[i] = 2.7 + Math.random()*2;d.write("<div id=\"snowFlakeDiv_"+ i +"\" style=\"position:absolute; z-index:11; visibility:visible; top: 15px; left: 215px;\"><img src=\"" + snowflake[snowFlakeImgNo] + "\" border=\"0\" id='snowImg_"+ i +"'></div>");
}function snowFlakeFloat() {
var now = new Date();
var second = now.getTime();
var scrollTop = document.body.scrollTop;
var snowflakeDiv_0 = d.getElementById("snowFlakeDiv_0");
var snowflakeDiv_1 = d.getElementById("snowFlakeDiv_1");
var snowflakeDiv_2 = d.getElementById("snowFlakeDiv_2");
var snowflakeDiv_3 = d.getElementById("snowFlakeDiv_3");
var snowflakeDiv_4 = d.getElementById("snowFlakeDiv_4");
var snowflakeDiv_5 = d.getElementById("snowFlakeDiv_5");
var snowflakeDiv_6 = d.getElementById("snowFlakeDiv_6");
var snowflakeDiv_7 = d.getElementById("snowFlakeDiv_7");
for (i = 0; i < no; i++) {
if (y_point[i] >= 0) {
y_point[i] += y_increased[i];
}
if (y_point[i] > scrollTop + body_height - 10 || y_point[i] < scrollTop || y_point[i] < 0) { // 移出窗口,或在等待队列
if ((second - lastTime) / 1000 > fallInterval) { // 从队列中下落
snowFlakeImgNo = Math.round(Math.random()*(snowflake.length-1));
if (document.getElementById('snowImg_'+i)) {
document.getElementById('snowImg_'+i).src = snowflake[snowFlakeImgNo];
}
x_point[i] = Math.random()*(body_width-x_length[i]-250) + 100;
y_point[i] = scrollTop;
x_increased[i] = 0.05 + Math.random()/2;
y_increased[i] = 2.7 + Math.random()/2;
// x_increased[i] = 0.05;
// y_increased[i] = 2.7;
body_width = oBody.clientWidth;
body_height = oBody.clientHeight;
lastTime = second;
}else {
y_point[i] = -50;
}}
x_sin[i] += x_increased[i];eval("snowflakeDiv_"+i).style.pixelTop = y_point[i];
eval("snowflakeDiv_"+i).style.pixelLeft = x_point[i] + x_length[i]*Math.sin(x_sin[i]);}
}window.setInterval("snowFlakeFloat()",100);
2. 在你需要的页面链接代码文件:<SCRIPT language=javascript src="漂浮.js"></SCRIPT>
3.
加入图片
代码为:
引用:
<SCRIPT language=JavaScript>
//我这只加了三张图片,其实你还可以多加几种图片,图片文件一般小。
var snowflake = new Array();
snowflake[0] ='float1.gif';//图片一
snowflake[1] ='float2.gif';//图片二
snowflake[2] ='float3.gif';//图片三
</SCRIPT>