function random(min, max) { return Math.floor(Math.random() * (1 + max - min) + min); } // setup var tl = new TimelineMax({ repeat: -1 }), container = $(".container"), html = "", isMobile = !!("ontouchstart" in window), dotsCount = isMobile ? 80 : 175; for (var i = 0; i < dotsCount; i++) { html += "
"; } var dots = $(html).appendTo(container); // animation dots.each(function() { tl.add(TweenMax.fromTo(this, 6, { left: random(0,100) + "%", top: random(0,100) + "%", z: random(-725,600), opacity: Math.random() }, { left: "+=" + random(-40,40) + "%", top: "+=" + random(-36,36) + "%", z: "+=" + random(-725,600), opacity: Math.random() + 0.1, repeat: 1, yoyo: true, ease: Sine.easeInOut }), 0); }); tl.fromTo(container, .8, { perspective: 50, opacity: .55 }, { perspective: 215, opacity: .9, ease: Sine.easeInOut }, 3.25) .to(container, .8, { perspective: 50, opacity: .55, ease: Sine.easeInOut }, 6.5);