JSFiddle - React, Tailwind, and code Playground
JavaScript
var no = 10;
var delai = 10;
var dx = new Array(),
xp = new Array(),
yp = new Array();
var am = new Array(),
stx = new Array(),
sty = new Array();
var i;
larg_fenetre = (document.body.offsetWidth < window.innerWidth) ? window.innerWidth : document.body.offsetWidth;
haut_fenetre = (document.body.offsetHeight < window.innerHeight) ? window.innerHeight : document.body.offsetHeight;
var iteration_max = 100;
var iteration = 0;
for (i = 0; i < no; i++) {
dx[i] = 0;
xp[i] = Math.random() * (larg_fenetre - 40);
yp[i] = Math.random() * haut_fenetre;
am[i] = Math.random() * 20;
stx[i] = 0.02 + Math.random() / 10;
sty[i] = 0.7 + Math.random();
obj = document.getElementsByTagName('body')[0];
para = document.createElement("img");
para.setAttribute("src", "img/fall.png");
para.setAttribute("id", "dot" + i);
para.style.position = "absolute";
para.style.zIndex = "2";
obj.appendChild(para);
}
function neige() {
for (i = 0; i < no; i++) {
dx[i] += stx[i];
yp[i] += sty[i];
if (yp[i] > haut_fenetre - 50) {
xp[i] = Math.random() * (larg_fenetre - am[i] - 40);
yp[i] = 0;
}
document.getElementById("dot" + i).style.top = yp[i] + "px";
document.getElementById("dot" + i).style.left = xp[i] + am[i] * Math.sin(dx[i]) + "px";
}
console.log(iteration);
if (iteration < iteration_max) {
setTimeout("neige()", delai);
iteration++;
}
}
neige();