let beer = document.querySelector('.beer'); function spawnBubble() { let bubble = document.createElement('span'); let rand = parseInt(Math.random() * (100 - 0) - 0); bubble.classList.add('bubble'); bubble.classList.add('start'); bubble.style.left = `${rand}%`; let timer = setTimeout(() => { beer.appendChild(bubble); setTimeout(() => { bubble.classList.remove('start'); }, 50); setTimeout(() => { bubble.remove(); clearTimeout(timer); }, 5000); }, parseInt(Math.random() * 1500)); } setInterval(() => { let rand = parseInt(Math.random() * (10 - -10) - 10); beer.style.webkitTransform = "rotate(" + rand + "deg)"; [...Array(20).keys()].forEach(spawnBubble); }, 1000);