I think my created divs are overloading the page. Is there a way to clear/destroy created elements after a certain period.
Here is the code but for better understanding please see: link
var ct = 0;
let max = 180;
let min = -180;
var xMrgn = 0;
var yMrgn = "440px";
function startCounter() {
if (ct < 50) {
var bbls = document.querySelector('.bbls-amount').value;
var bblSpeed = document.querySelector('.bbls-speed').value;
document.getElementById('bblsQty').innerHTML = bbls
var b = Math.floor(Math.random() * (bbls - 3 + 1) + 3);
for (let i = 0; i < b; i++) {
var a = Math.floor(Math.random() * (max - min + 1) + min);
xMrgn = a + "px";
let div = document.createElement('div');
div.className = 'bubbles';
dv.appendChild(div);
var msxS = bblSpeed * 14;
var minS = bblSpeed * 6;
var s = Math.floor(Math.random() * (msxS - minS + 1) + minS);
$(".bubbles").animate({
"marginLeft": xMrgn,
"bottom": yMrgn
}, s);
}
}
document.getElementById('txt').innerHTML = ct;
var counter = setTimeout(startCounter, 1000);
ct = (ct < 50) ? ct + 1 : 0;
}
startCounter()
There was a lot of confusing variable names and a lot of "var"s so I've changed the code quite a bit for when I had to understand what everything meant.
Here's a solution much closer to your original code:
When coding try to avoid unreadable variable names, especially if you want someone else to read it, for example on stack overflow. If you want to keep the shorter variable names, please leave comments for what the variables are and how they are used. It is highly appreciated.