以下是 JS圣诞节雪花网页背景网易精简版特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="JS代码,其他代码,JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为JS圣诞节雪花网页背景网易精简版" />
<title>JS圣诞节雪花网页背景网易精简版</title>
<link href="css/lrtk.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- 代码 开始 -->
<span class="toolbar">adasdfsad</span>
<div class="g-body">
<div style="text-align:center;padding:150px 0 20px 0">
<p><div>JS圣诞节雪花网页背景网易精简版,HTML5特效,代码简洁易用,适用于圣诞节、元旦、春节。兼容主流浏览器!<br /><br />使用方法:<br />1、在head区域引入样式表文件lrtk.css<br />2、在head区域引入<div class="g-body"></div> 网页的主体放在这里。<br />3、在你的网页中加入3段<canvas>图形容器<br />4、引入JS <script type="text/javascript" src="js/snow.min.js"></script><br />5、背景图片和网页宽度请自行根据自己的需求修改。</div></p>
<p style="margin:20px 0"></p>
</div>
</div>
<canvas id="snowFallTop" class="snowFall snowFallTop" width="1220" height="162" style="left: 321px;"></canvas>
<canvas id="snowFallLeft" class="snowFall snowFallLeft" width="321" height="742" style="width: 321px;"></canvas>
<canvas id="snowFallRight" class="snowFall snowFallRight" width="321" height="742" style="width: 321px;"></canvas>
<script type="text/javascript" src="js/snow.min.js"></script>
<!-- 代码 结束 -->
</body>
</html>
JS代码(snow.min.js):
(function(){
if(navigator.userAgent.indexOf("MSIE 6.0")>0||navigator.userAgent.indexOf("MSIE 7.0")>0||navigator.userAgent.indexOf("MSIE 8.0")>0){
return}
var f=20;
var v=0.7;
var g=0;
var n=0.8;
var m=0;
var d=document.getElementById("snowFallTop");
var x=document.getElementById("snowFallLeft");
var e=document.getElementById("snowFallRight");
var q=d.clientWidth;
var o=d.clientHeight;
d.width=q;
d.height=o;
b();
var l=d.getContext("2d");
var t=x.getContext("2d");
var k=e.getContext("2d");
l.fillStyle="#fff";
t.fillStyle="#fff";
k.fillStyle="#fff";
g=o*v;
m=(o-g)*n;
var h=function(){
this.x=0;
this.y=0;
this.velocityX=0;
this.velocityY=0;
this.radius=0;
this.transparency=0;
this.clientWidth=0;
this.clientHeight=0;
this.reset()}
;
h.prototype.reset=function(){
this.x=Math.random()*this.clientWidth;
this.y=Math.random()*-this.clientHeight;
this.velocityX=0.5-Math.random();
this.velocityY=(1+Math.random())*3;
this.radius=(1+Math.random())*2;
this.transparency=(0.5+Math.random())*0.5}
;
var u=[],c,a=[],w=[],p=[];
for(var r=0;
r<f;
r+=1){
a.push(i(new h(),d));
w.push(i(new h(),x));
p.push(i(new h(),e))}
function i(z,y){
z.clientWidth=y.width;
z.clientHeight=y.height;
z.reset();
return z}
function j(){
l.clearRect(0,0,d.width,d.height);
t.clearRect(0,0,x.width,x.height);
k.clearRect(0,0,e.width,e.height);
s(l,a);
s(t,w);
s(k,p);
requestAnimFrame(j)}
function s(B,y){
var z=null;
for(var A=0;
A<f;
A+=1){
z=y[A];
z.x+=z.velocityX;
z.y+=z.velocityY;
B.globalAlpha=z.transparency;
B.beginPath();
B.arc(z.x,z.y,z.radius,0,Math.PI*2,false);
B.closePath();
B.fill();
if(z.y>z.clientHeight){
z.reset()}
}
}
function b(){
d.style.left=((document.body.clientWidth-1220)/2)+"px";
if(document.body.clientWidth-1220>20){
x.width=(document.body.clientWidth-1220)/2;
x.height=742;
x.style.width=x.width+"px";
e.width=(document.body.clientWidth-1220)/2;
e.height=742;
e.style.width=x.width+"px"}
}
window.requestAnimFrame=(function(){
return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(y){
window.setTimeout(y,1000/60)}
}
)();
requestAnimFrame(j);
window.addEventListener("resize",function(){
b();
l.fillStyle="#fff";
t.fillStyle="#fff";
k.fillStyle="#fff"}
,false)}
)();
CSS代码(lrtk.css):
/* ����ͼ�� �Ѽ����� www.lanrentuku.com */
body{margin:0;font-size:12px;line-height:1.666;}
.g-body{background:url("../images//body_bg.png") center top no-repeat;background-color:#FFF;height:1000px}
.toolbar{height:31px;line-height:29px;color:#8e8e8e;background:#f5f6f8;display:block;text-align:center}
/* ��ҳ */
.snowFall{position:absolute;top:0;z-index:3;pointer-events:none;_display:none;color:#ffffff;}
.snowFallTop{left:0;width:1220px;height:162px;}
.snowFallLeft{left:0;height:742px;z-index:3;}
.snowFallRight{right:0;height:742px;z-index:3;}