JSFiddle - React, Tailwind, and code Playground

by mrjordy

HTML

<div class="covidContainer"> 
<div class="covidVertGrad"></div>
<div class="covidHorizGrad"></div>
<div class="covidImage"></div>
<div class="covidVertGradOverlay"></div>
 <div class="covidFloaters"> 
  <div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge"></div><div class="debris floaterLarge floaterX"></div>

  <div class="debris floaterMedium floaterX"></div><div class="debris floaterMedium"></div><div class="debris floaterMedium"></div><div class="debris floaterMedium floaterX"></div><div class="debris floaterMedium"></div><div class="debris floaterMedium"></div><div class="debris floaterMedium floaterX"></div><div class="debris floaterMedium"></div><div class="debris floaterMedium"></div><div class="debris floaterMedium floaterX"></div><div class="debris floaterMedium"></div><div...

CSS

.covidContainer {
  height: 412px;
  width: 100%;
  overflow: hidden;
  position: relative;
}
.covidVertGrad {
  height: 412px;
  width: 100%;
  background: linear-gradient(to top, #02121b, #02223b, #01233f, #0d2d4b, #00203f);
  position: absolute;
}
.covidHorizGrad {
  height: 412px;
  width: 100%;
  background: linear-gradient(to left, black, white);
  opacity: 0.15;
  position: absolute;
}
.covidImage {
    background: url(https://mp-dev.cloud.navy.mil/homeCovid.png);
    height: 412px;
    width: 1053px;
    position: absolute;
    right: 40%;
}
@media only screen and (min-width: 1773px) {
  .covidImage {
    right: auto;
    left: 0;
  }
}
.covidVertGradOverlay {
    height: 200px;
    bottom: 0;
    width: 100%;
    background: linear-gradient(to top, #00303f 2%, transparent);
    opacity: 0.35;
    position: absolute;
}
.floaterLarge {
  background: radial-gradient(rgba(255,255,255,.5), white 80%, rgba(255,255,255,.1) 100%);
  box-shadow: 0 0 4px white;
  border-radius: 16px;
  width: 16px;
  height: 16px;
  position: absolute;
  opacity: .05;
}
.floaterMedium {
  background: radial-gradient(rgba(255,255,255,.8), white 40%, rgba(255,255,255,.1) 100%);
  box-shadow: 0 0 4px white;
  border-radius: 8px;
  width: 8px;
  height: 8px;
  position: absolute;
  opacity: .05;
}
.floaterBlur {
  background: white;
  box-shadow: 0 0 10px 18px white;
  border-radius: 3px;
  width: 2px;
  height: 2px;
  position: absolute;
  opacity: .05;
}
.floaterX {
  width: 12px;
}

.floaterX:nth-of-type(even) {
transform:rotate(45deg);
}
.floaterX:nth-of-type(odd) {
transform:rotate(-45deg);
}

JavaScript

// collect all the divs
var divs = document.getElementsByClassName('debris');
// get window width and height
var winWidth = window.innerWidth;
var winHeight = 800;

// i stands for "index". you could also call this banana or haircut. it's a variable
for ( var i=0; i < divs.length; i++ ) {
 	
    // shortcut! the current div in the list
    var thisDiv = divs[i];
    
    // get random numbers for each element
    randomTop = getRandomNumber(0, winHeight);
    randomLeft = getRandomNumber(0, winWidth);
    
    // update top and left position
    thisDiv.style.top = randomTop +"px";
    thisDiv.style.left = randomLeft +"px";
    
}

// function that returns a random number between a min and max
function getRandomNumber(min, max) {
    
  return Math.random() * (max - min) + min;
    
}