I have an animated background in the works.
What I'm aiming for is for the "bubbles" to travel in a random trajectory at a random velocity. Upon reaching the edge of the screen, it teleports back to the opposite side to continue the path.
I would do the animation through CSS, but I want the path each "bubble" follows to be random.
Something like this for each element.
How would I achieve this effect through JavaScript?
This is the project in it's current state.
Codepen : https://codepen.io/JosephChunta/pen/WNrKxeY
Current JavaScript
const orderedNumber = document.querySelectorAll('.backgroundBubble');
var colors = [
'#ff5b00', '#b8d500', '#795ced',
'#ab004a', '#21aec0', '#fe9300'
];
for (li of orderedNumber) {
var random_color = colors[Math.floor(Math.random() * colors.length)];
li.style['background'] = random_color;
var random_dimensions = Math.floor(Math.random() * 20 + 5);
li.style['width'] = random_dimensions + "px";
li.style['height'] = random_dimensions + "px";
var random_left = Math.floor(Math.random() * 99 + 1);
li.style['left'] = random_left + "%";
var random_top = Math.floor(Math.random() * 99 + 1);
li.style['top'] = random_top + "%";
}
"Bubble" HTML
<div class="context">
<h1>Hello</h1>
</div>
<div class="area">
<ul class="circles">
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
<li class="backgroundBubble"></li>
</ul>
</div>

