Robert Crocker

Craft obsessed developer who designs.

← Back to the lab

52Reduced Motion

III · Particles & Play

The same burst, gated by prefers-reduced-motion in both CSS and JS.

Click

Source

3 files
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CodeSandbox</title>
  </head>
  <body>
    <style>
      {/*
        CHEATSHEET
        
        Basic media query:
        @media (prefers-reduced-motion: no-preference) {
          // Apply enhanced, animated experience here
        }
      */}
      
      @keyframes fadeToTransparent {
        to {
          opacity: 0;
        }
      }
      @keyframes disperse {
        to {
          transform:
            translate(
              calc(cos(var(--angle)) * var(--distance)),
              calc(sin(var(--angle)) * var(--distance))
            )
            rotate(var(--rotation));
        }
      }
      
      .star {
        position: absolute;
        user-select: none;
        pointer-events: none;
        animation:
          disperse 1000ms forwards cubic-bezier(0.26, 0.95, 0.00, 1.00),
          fadeToTransparent var(--fade-duration) var(--fade-delay) forwards;
      }
    </style>
    
    
    
    <!--
      This hidden image is added so that the browser will download
      the image on page load. That way, it’s ready and waiting when
      the user triggers the particle effect.
    -->
    <img
      alt=""
      src="https://sandpack-bundler.vercel.app/img/wand-sparkle.svg"
      style="display: none"
    />
  </body>
</html>