余志国网站设计工作室是专业从事义乌网站建设、义乌外贸网站建设、义乌网站制作、义乌网站设计的专业义乌网站建设工作室,是义乌外贸网站建设专家!

冬天来了,给自己网站加飘雪花效果

分类:网页设计 Tags: 网页特效 javascript 评论:0 浏览:6446 最近更新时间:2008/10/7 22:00:35

是否感觉到冬天已经离你很近,前段时间做了一个圣诞礼品网站http://www.ywjunkang.com,用到了飘雪花效果,现在共享给大家!
1,把下面代码保存为:snow.js ,也可以点下面直接下载:
http://www.yuzhiguo.com/pic/file1/snow.rar
 
  1. // JavaScript Document
  2.   //Configure below to change URL path to the snow image
  3.   var snowsrc="/images/snow.gif"
  4.   // Configure below to change number of snow to render
  5.   var no = 10;
  6.   // Configure whether snow should disappear after x seconds (0=never):
  7.   var hidesnowtime = 0;
  8.   // Configure how much snow should drop down before fading ("windowheight" or "pageheight")
  9.   var snowdistance = "pageheight";
  10.  
  11. ///////////Stop Config//////////////////////////////////
  12.  
  13.   var ie4up = (document.all) ? 1 : 0;
  14.   var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
  15.  
  16.     function iecompattest(){
  17.     return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  18.     }
  19.  
  20.   var dx, xp, yp;    // coordinate and position variables
  21.   var am, stx, sty;  // amplitude and step variables
  22.   var i, doc_width = 800, doc_height = 600; 
  23.   
  24.   if (ns6up) {
  25.     doc_width = self.innerWidth;
  26.     doc_height = self.innerHeight;
  27.   } else if (ie4up) {
  28.     doc_width = iecompattest().clientWidth;
  29.     doc_height = iecompattest().clientHeight;
  30.   }
  31.  
  32.   dx = new Array();
  33.   xp = new Array();
  34.   yp = new Array();
  35.   am = new Array();
  36.   stx = new Array();
  37.   sty = new Array();
  38.   snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : snowsrc
  39.   for (i = 0; i < no; ++ i) {  
  40.     dx[i] = 0;                        // set coordinate variables
  41.     xp[i] = Math.random()*(doc_width-50);  // set position variables
  42.     yp[i] = Math.random()*doc_height;
  43.     am[i] = Math.random()*20;         // set amplitude variables
  44.     stx[i] = 0.02 + Math.random()/10; // set step variables
  45.     sty[i] = 0.7 + Math.random();     // set step variables
  46.         if (ie4up||ns6up) {
  47.       if (i == 0) {
  48.         document.write("<DIV id='\"dot"+' i=""><IMG alt="" src='"+snowsrc+"' border='\"0\"' _fcksavedurl='"+snowsrc+"'><\/div>");
  49.       } else {
  50.         document.write("<DIV id='\"dot"+' i=""><IMG alt="" src='"+snowsrc+"' border='\"0\"' _fcksavedurl='"+snowsrc+"'><\/div>");
  51.       }
  52.     }
  53.   }
  54.  
  55.   function snowIE_NS6() {  // IE and NS6 main animation function
  56.     doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
  57.         doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance
  58. =="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
  59.     for (i = 0; i < no; ++ i) {  // iterate for every dot
  60.       yp[i] += sty[i];
  61.       if (yp[i] > doc_height-50) {
  62.         xp[i] = Math.random()*(doc_width-am[i]-30);
  63.         yp[i] = 0;
  64.         stx[i] = 0.02 + Math.random()/10;
  65.         sty[i] = 0.7 + Math.random();
  66.       }
  67.       dx[i] += stx[i];
  68.       document.getElementById("dot"+i).style.top=yp[i]+"px";
  69.       document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
  70.     }
  71.     snowtimer=setTimeout("snowIE_NS6()", 10);
  72.   }
  73.  
  74.     function hidesnow(){
  75.         if (window.snowtimer) clearTimeout(snowtimer)
  76.         for (i=0; i0)
  77.         setTimeout("hidesnow()", hidesnowtime*1000)
  78.         }</DIV></DIV>
2,把下面代码插入到要飘雪花效果的网页中: 
 
  1. <script language="javascript" type="text/javascript" src="snow.js"></script>
3,把下面图片保存到/images/snow.gif
http://www.yuzhiguo.com/pic/images3/snow.gif(最好是右键目标另存为保存该图片,因为图片本身是白色的,直接点击可能看不到)

提醒:注意各个图片及文件路径!

本文地址:/376/
  • 相关文章
  • 推荐文章
  • 最新文章
发表评论





您的IP:18.97.14.91,来自:

留言

 


免费咨询
建站咨询热线
15967985565
QQ: 358758308 Skype: yuzhiguo Facebook: yuzhiguo Email