JSFiddle - React, Tailwind, and code Playground

by BurpmanJunior

CSS

.debris {
    background-color: #000;
    height: 16px;
    position: fixed;
    width: 16px;
    border-radius: 8px;
    -webkit-animation-name: particle;
    -webkit-animation-duration: 500ms;
    -webkit-animation-iteration-count: 1;
    -webkit-animation-fill-mode: forwards;
    user-select: none;
}

html,body {
    background-color: #fff;
    overflow: hidden;
}

@-webkit-keyframes particle{
    0%{
        transform: scaleX(0.3) scaleY(0.3);
        opacity: 1;
    }
    100%{
        transform: scaleX(0.1) scaleY(0.1);
        opacity: 0;
    }
}

JavaScript

/**
 * Debris
 */
var particleCount = 30;

function Debris(center, angle, iteration) {
    var element = document.createElement('div');
    var velocityX = Math.cos((1 + (angle * Math.random())) * Math.PI / 180);
    var velocityY = Math.sin((1 + (angle * Math.random())) * Math.PI / 180);
    var currentX = center.x;
    var currentY = center.y;
    var animationId;
    var parentElem;
    var runTime = 0;
    var dropFactor = 0;
    
    element.className = 'debris';
    element.style.left = currentX.toString() + 'px';
    element.style.top = currentY.toString() + 'px';
    
    dropFactor = 0.01 * dropFactor;
    
    this.appendTo = function(parentElement) {
        parentElem = parentElement;
        parentElement.appendChild(element);
    };
    
    this.remove = function() {
        if(element.parentNode) {
            element.parentNode.removeChild(element);
        }
    };
    
    this.stopAnimating = function() {
        clearTimeout(animationId);
    };
    
    var _this = this;
    
    animationId = setInterval(function() {
        runTime += 16;
        
        currentX += velocityX * 5;
        currentY += velocityY * 5;
        
        velocityX += 0.05 - 0.1 * Math.random();
        velocityY += (0.05 + dropFactor) - 0.1 * Math.random();
        
        element.style.left = currentX.toString() + 'px';
        element.style.top = currentY.toString() + 'px';
        
        if(
            currentX > window.innerWidth + 10 ||
            currentY > window.innerHeight + 10 ||
            currentY < -10 ||
            currentX < -10 ||
            runTime > 500
        ){
            parentElem.removeChild(element);
            _this.stopAnimating();
        }
        
    }, 16);
}


function throttle(fn, threshhold, scope) {
    // Define default if not;
    threshhold || (threshhold = 250);
    // Setup vars
    var last,
    deferTimer;
    // Main func
    return function () {
        // Applied to
        var context = scope || this;
   ...