1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/******************************************
* Titre: De la neige !!!
* Réécrit par Spacefrog
* Date: 12/2009
******************************************/
var IsIE6 = (!!document.all && !window.XMLHttpRequest )
//var ext= (/(?!=compatible;\s)MSIE\s6/i.test(navigator.userAgent))?'gif':'png';
var ext=(IsIE6)?'gif':'png';
var IsIE=!!document.all;
var snowsrc=new Image();
snowsrc.src="images/snowflake."+ext
var snowsrc1= new Image;
snowsrc1.src="images/snowflake1." +ext
// Configure below to change number of snow to render
var densite = 50;
var dx, xp, yp; // coordinate and position variables
var am, vx, vy; // amplitude and step variables
var i, doc_width , doc_height ;
var vitesseH = 1 //coefficient de vitesse de balancement
var changevent=true // pour ajouter la variation du sens et de l'intesité du vent
var vent =new Array(10,0,-10,-20,0,-5,-10,-5,-3,0,2,3,5,10,20,30,50,60,80,70,50,30,10,0,-1,-5,-10,-20);//Vent de travers positif=> G à D _ négatif => D à G.
var forceH=0;
var drift=10;
var changechute=true
var chute= new Array(1,2,3,2,1,1,2,3,4,5,4,3,5,4,6,4,2,3,2,1,1,1,1,1,1) //Vitesse de chute des flocons de 1 à 10
var forceV=0
var vitesseV = 1 //coefficient de vitesse de chute
var dx = new Array();
var xp = new Array();
var yp = new Array();
var am = new Array();
var vx = new Array();
var vy = new Array();
function init(){
if (self!=parent){
document.body.parentNode.parentNode.firstChild.nodeValue = 'doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"';
}
doc_width =(self!=top)?top.frames[0].document.body.offsetWidth:self.document.body.offsetWidth;
doc_height =(self!=top)?top.frames[0].document.body.offsetHeight:self.document.body.offsetHeight;
densite=Math.floor(doc_width/12);
var flake= document.createElement('img');
flake.style.border='0';
flake.style.width="auto";
flake.style.height="auto";
flake.style.position='absolute';
flake.style.top='15px';
flake.style.left='15px';
flake.style.display="none";
//Position des flocons
var i=0;
while (i < densite) {
dx[i] = 0; // set coordonnés variables
xp[i] = Math.random()*(doc_width-50); // positions variables
yp[i] = Math.random()*doc_height;
am[i] = Math.random()*40; // amplitude de balancement
vx[i] = 0.02 + Math.random()/10 * vitesseH; // vitesse horizontale variable
vy[i] = 0.9 + Math.random() * vitesseV; // vitesse verticale variable
var opacite=Math.random()*100;
var newflake=flake.cloneNode(true);
newflake.id="flocon"+i;
newflake.zIndex=i+1;
newflake.src=(i % 2==0)?snowsrc.src:snowsrc1.src;
if(!document.all){newflake.style.height=20-(Math.floor((Math.random()*8)))+"px"}
IsIE?newflake.style.filter="alpha(opacity="+opacite+")":newflake.style.opacity=opacite/100;
document.body.appendChild(newflake);
i++
}
var neige=setInterval(function(){snow()},30);
if (changevent==true){ var girouette=setInterval(function(){wind()},4250);
}
if (changechute==true){ var intesite=setInterval(function(){fall()},7130);
}
}
function wind(){
drift = vent[forceH]
forceH++
forceH=(forceH>vent.length)?0:forceH;
}
function fall() {
vitesseV = chute[forceV]
forceV++
forceV=(forceV>chute.length-1)?0:forceV;
}
function snow() {
//doc_width = document.body.offsetWidth;
//doc_height = document.body.offsetHeight;
doc_width =(self!=top)?top.frames[0].document.body.offsetWidth:self.document.body.offsetWidth;
doc_height =(self!=top)?top.frames[0].document.body.offsetHeight:self.document.body.offsetHeight;
var i=0;
while (i < densite) {
yp[i] += vy[i];
if (yp[i] > doc_height-20) {
xp[i] = (Math.random()*(doc_width-am[i]-30));
yp[i] = 0;
vx[i] = (0.02 + Math.random()/10)*vitesseH;
vy[i] = (0.7 + Math.random())*vitesseV;
}
dx[i] += vx[i];
document.getElementById("flocon"+i).style.display="block"
document.getElementById("flocon"+i).style.top = yp[i]+"px";
if (drift>0){
xp[i]=((xp[i]+drift/10)>doc_width)?-40:xp[i]+drift/10;
}
if (drift<0){
xp[i]=((xp[i]+drift/10)<-40)?doc_width:xp[i]+drift/10;
}
document.getElementById("flocon"+i).style.left = xp[i] + am[i]*Math.sin(dx[i])+"px";
i++
}
} |
Partager