$(document).ready(function(){ function addLine() { var windowWidth = $('body').innerWidth(); var line = $(''); var length = Math.floor((Math.random() * 400) + 50); var position = Math.floor((Math.random() * windowWidth)); var rotation = Math.floor((Math.random() * 360) + 1); var speed = Math.floor((Math.random() * 15000) + 1500); var top = $('body').height() + length; line.css({ 'width' : length, 'left' : position, 'transform': 'rotate(' + rotation + 'deg)' }); line.appendTo('body').animate({ 'bottom': "+=" + top, opacity: 0, }, speed, function() { line.remove(); }); } window.setInterval(function(){ addLine(); }, 25); });