提示:您可以先修改部分代碼再運行
<html><head><meta name="GENERATOR" content="Microsoft FrontPage 6.0"><meta name="ProgId" content="FrontPage.Editor.Document"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>js特效下雪效果代碼</title></head><body onLoad="cl0();"><div>開啟效果<br /><br /></div><script language="javascript">var snowflake = new Array(); function getimg(piao){snowflake=piao.split(',');}//window.onload=function()//{getimg('yun_qi_img/banner.gif,yun_qi_img/banner.gif,yun_qi_img/banner.gif');//}</script><script language="javascript">var showimg=1;var no = 18 ;//同期顯示圖片數var speed=100;//下降速度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;var num;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;var floatDiv="";/**/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 +"" ></div>"); //floatDiv=floatDiv+"<div id="snowFlakeDiv_"+ i +"" ></div>";}function snowFlakeFloat(num) { var now = new Date(); var second = now.getTime(); var scrollTop = document.body.scrollTop;if (num==1) { 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) / 2000 > 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]; document.getElementById("snowflakeDiv_"+i).style.pixelTop = y_point[i]; document.getElementById("snowflakeDiv_"+i).style.pixelLeft = x_point[i] + x_length[i]*Math.sin(x_sin[i]); }}else{for (i=0;i<no;i++) { document.getElementById("snowflakeDiv_"+i).style.display="none"; }}}function cl0() {for (i=0;i<no;i++) { document.getElementById("snowflakeDiv_"+i).style.display="none"; }}var t=null;function cl() {if(showimg){for (i=0;i<no;i++) { document.getElementById("snowflakeDiv_"+i).style.display="block"; }t=window.setInterval("snowFlakeFloat(1)",speed);showimg=0;document.getElementById("showbutton").innerHTML='關閉效果';}else{ snowFlakeFloat(2); showimg=1; window.clearTimeout(t); document.getElementById("showbutton").innerHTML='開啟效果';}}</script></body></html>
提示:您可以先修改部分代碼再運行