Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="confetti-box">
  <div id="info-box">
    <span>Click Anywhere</span>
    <a href="https://twitter.com/smpnjn" target="_top">Follow on Twitter</a>
  </div>
</div>
<div id="highlight-position">
  
 </div>

              
            
!

CSS

              
                body {
  background: linear-gradient(90deg, #20005f, #00035a);
  user-select: none;
}

#info-box {
  position: absolute;
  bottom: 0;
  right: 0;
  padding: 2rem;
  color: white;
  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  letter-spacing: 1px;
  font-size: 1.25rem;
  text-transform: uppercase;
  font-weight: 500;
}
#info-box > span, #info-box a {
  display: block;
  color: white;
  padding: 0 0 0.25rem 0;
  margin: 0 0 0.5rem 0;
  text-align: right;
  text-decoration: none;
}

#info-box span {
  font-weight: 800;
}

#info-box a { 
  border-bottom: 1px solid rgba(255,255,255,0.5);
}
#highlight-position {
    width: 50px;
    height: 50px;
    border-radius: 100px;
    box-shadow: 0 2px 25px rgb(0 90 255 / 16%);
    position: absolute;
    top: 0;
    will-change: left, top;
    left: 0;
    border: 2px solid rgb(174 184 255 / 25%);
    pointer-events: none;
    opacity: 0;
}
#confetti-box {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.confetti {
  position: absolute;
  z-index: 9999;
}

.confetti-item {
  width: 10px;
  position: absolute;
  top: 0;
  left: 0;
  height: 10px;
}
              
            
!

JS

              
                /* Random Id generator for giving confetti elements unique IDs */
const randomId = function(length) {
    var result = [];
    var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
      result.push(characters.charAt(Math.floor(Math.random() * 
 charactersLength)));
   }
   return result.join('');
}

/* Short function to create confetti at x, y with confettiItems number of items */
const createConfetti = function(x, y, confettiItems) {
    let createElement = document.createElement('div');
    createElement.classList.add('confetti');
    let makeId = randomId(10);
    createElement.setAttribute('data-id', makeId);
    let confettiHTML = '';
    let colors = [ '#2162ff', '#9e21ff', '#21a9ff', '#a9ff21', '#ff2184' ]
    
    for(var i = 0; i < confettiItems; ++i) {
        let color = Math.floor(Math.random() * (colors.length));
        confettiHTML += `<div class="confetti-item" style="background-color: ${colors[color]};" data-angle="${Math.random()}" data-speed="${Math.random()}"></div>`;
        confettiHTML += `<div class="confetti-item reverse" style="background-color: ${colors[color]};" data-angle="${Math.random()}" data-speed="${Math.random()}"></div>`;
    }
    
    createElement.style.position = `fixed`;
    createElement.style.top = `${y}px`;
    createElement.style.left = `${x}px`;
    createElement.innerHTML = confettiHTML;
    document.body.appendChild(createElement);
    
    let gravity =  50; // Fjolt is a high gravity planet
    let maxSpeed = 105000; // Pixels * 1000
    let minSpeed = 65000; // Pixels * 1000
    let t = 0; // Time starts at 0
    let maxAngle = 1500; // Radians * 1000
    let minAngle = 400; // Radians * 1000
    let opacity = 1;
    let rotateAngle = 0;

    let interval = setInterval(function() {
        document.querySelectorAll(`[data-id="${makeId}"] .confetti-item`).forEach(function(item) {
            let modifierX = 1;
            let modifierY = 1;
            if(item.classList.contains('reverse')) {
                modifierX = -1;
            }
            item.style.opacity = opacity;
            let randomNumber = parseFloat(item.getAttribute('data-angle'));
            let otherRandom = parseFloat(item.getAttribute('data-speed'));
            let newRotateAngle = randomNumber * rotateAngle;
            let angle = (randomNumber * (maxAngle - minAngle) + minAngle) / 1000;
            let speed = (randomNumber * (maxSpeed - minSpeed) + minSpeed) / 1000;
            let realT = t * (parseFloat(item.getAttribute('data-angle')));
            let x = speed * t * Math.cos(angle) + (50 * otherRandom * t);
            let y = speed * t * Math.sin(angle) - (0.5 * gravity * Math.pow(t, 2))  + (50 * otherRandom * t);
            item.style.transform = `translateX(${x * modifierX}px) translateY(${y * -1 * modifierY}px) rotateY(${newRotateAngle}deg) scale(${1})`;
        })
        t += 0.1;
        rotateAngle += 3;
        opacity -= 0.02;
        if(t >= 6) {
            t = 0.1;
            if(document.querySelector(`[data-id="${makeId}"]`) !== null) {
                document.querySelector(`[data-id="${makeId}"]`).remove();
            }
            clearInterval(interval);
        }
    }, 33.33);
}

document.addEventListener('DOMContentLoaded', function(e) {
  document.getElementById('confetti-box').addEventListener('pointerdown', function(e) {
    createConfetti(e.pageX, e.pageY, 20);
  });
  document.getElementById('highlight-position').addEventListener('pointerdown', function(e) {
    createConfetti(e.pageX, e.pageY, 20);
  });
  document.getElementById('confetti-box').addEventListener('pointermove', function(e) {
    document.getElementById('highlight-position').style.opacity = 1;
    document.getElementById('highlight-position').style.top = `${e.pageY - 25}px`;
    document.getElementById('highlight-position').style.left = `${e.pageX - 25}px`;
    
  });
});
              
            
!
999px

Console