$(document).ready(function () { var colors = new Array("red", "yellow", "blue"); var size = 3; var startPos = -1; var speed = 2000; var cantidad = 500; setInterval(function () { var color = colors[random(0, 3)]; var w = window.innerWidth; var h = window.innerHeight; var e = document.createElement("span"); $(e).css("display", "inline-block"); $(e).css("width", size + "px"); $(e).css("height", size + "px"); $(e).css("background", color); $(e).css("position", "fixed"); $(e).css("top", startPos + "px"); $(e).css("left", random(0, w) + "px"); $(e).css("z-index", "1000"); $(e).animate({ top: h + "px" }, speed, function () { this.remove(); }); $("html").append(e); }, cantidad); }); function random(min, max) { return Math.floor((Math.random() * max) + min); }