{
  "format": "putcode/playground@1",
  "id": "a8807d44-6741-4a06-867d-b25822e30cda",
  "url": "https://putcode.dev/u/mighil/s/v9ovkpjqw5",
  "title": "GSAP Snowfall",
  "description": "A richer snowfall animation powered by the GSAP npm package. Uses staggered, randomized flakes with gentle sideways drift, rotation and varied fall durations.",
  "category": "animations",
  "tags": [
    "gsap",
    "snowfall",
    "npm",
    "animation",
    "javascript"
  ],
  "visibility": "public",
  "status": "published",
  "revision": 1,
  "author": "mighil",
  "forked_from": null,
  "created_at": "2026-12-02T18:51:56.042Z",
  "updated_at": "2026-12-02T18:53:59.043Z",
  "published_at": "2026-12-02T18:53:59.043Z",
  "source": {
    "html": "<main class=\"gsap-winter\">\n  <section class=\"gsap-winter__content\">\n    <p class=\"eyebrow\">A QUIET WINTER NIGHT</p>\n    <h1>Let it snow.</h1>\n    <p>Soft flakes, drifting through the night.</p>\n  </section>\n  <div class=\"gsap-snow\" aria-hidden=\"true\"></div>\n</main>",
    "css": ".gsap-winter {\n  position: relative;\n  min-height: 100vh;\n  overflow: hidden;\n  isolation: isolate;\n  display: grid;\n  place-items: center;\n  color: #f7fbff;\n  background:\n    radial-gradient(ellipse at 50% 110%, rgba(56, 104, 143, .45), transparent 55%),\n    linear-gradient(180deg, #071426 0%, #102b46 58%, #183b58 100%);\n  font-family: Inter, ui-sans-serif, system-ui, sans-serif;\n}\n\n.gsap-winter__content {\n  position: relative;\n  z-index: 1;\n  padding: 2rem;\n  text-align: center;\n  pointer-events: none;\n}\n\n.gsap-winter__content .eyebrow {\n  margin: 0 0 1rem;\n  color: #a9c7df;\n  font-size: .7rem;\n  font-weight: 700;\n  letter-spacing: .24em;\n}\n\n.gsap-winter__content h1 {\n  margin: 0;\n  font-size: clamp(3rem, 9vw, 6.5rem);\n  font-weight: 500;\n  letter-spacing: -.065em;\n}\n\n.gsap-winter__content p:last-child {\n  margin: 1rem 0 0;\n  color: #c0d1df;\n  font-size: clamp(.9rem, 2vw, 1.1rem);\n}\n\n.gsap-snow {\n  position: absolute;\n  z-index: 2;\n  inset: 0;\n  overflow: hidden;\n  pointer-events: none;\n}\n\n.gsap-snow__flake {\n  position: absolute;\n  top: -24px;\n  left: 0;\n  display: block;\n  border-radius: 50%;\n  background: #fff;\n  box-shadow: 0 0 9px rgba(220, 241, 255, .65);\n  will-change: transform;\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .gsap-snow__flake {\n    display: none;\n  }\n}",
    "js": "import { gsap } from \"https://esm.sh/gsap@3.12.5\";\n\nconst snowLayer = document.querySelector(\".gsap-snow\");\n\nif (snowLayer && !snowLayer.dataset.initialized) {\n  snowLayer.dataset.initialized = \"true\";\n\n  const reduceMotion = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  const flakeCount = 110;\n\n  if (!reduceMotion) {\n    const fragment = document.createDocumentFragment();\n    const flakes = [];\n\n    for (let i = 0; i < flakeCount; i += 1) {\n      const flake = document.createElement(\"i\");\n      flake.className = \"gsap-snow__flake\";\n\n      const size = gsap.utils.random(2, 7);\n      const startX = gsap.utils.random(0, window.innerWidth);\n      const duration = gsap.utils.random(7, 17);\n      const drift = gsap.utils.random(-110, 110);\n\n      gsap.set(flake, {\n        x: startX,\n        y: gsap.utils.random(-window.innerHeight, 0),\n        width: size,\n        height: size,\n        opacity: gsap.utils.random(0.25, 0.9),\n        scale: gsap.utils.random(0.75, 1.2)\n      });\n\n      fragment.appendChild(flake);\n      flakes.push({ flake, duration, drift, size });\n    }\n\n    snowLayer.appendChild(fragment);\n\n    flakes.forEach(({ flake, duration, drift }) => {\n      const fall = () => {\n        const currentX = gsap.getProperty(flake, \"x\");\n        const nextX = currentX + drift;\n\n        gsap.fromTo(\n          flake,\n          { y: -24, x: currentX, rotation: 0 },\n          {\n            y: window.innerHeight + 30,\n            x: nextX,\n            rotation: gsap.utils.random(-180, 180),\n            duration,\n            ease: \"none\",\n            onComplete: () => {\n              gsap.set(flake, {\n                y: -24,\n                x: gsap.utils.random(0, window.innerWidth)\n              });\n              fall();\n            }\n          }\n        );\n      };\n\n      gsap.delayedCall(gsap.utils.random(0, duration), fall);\n    });\n\n    window.addEventListener(\"resize\", () => {\n      flakes.forEach(({ flake }) => {\n        const x = gsap.getProperty(flake, \"x\");\n        if (x > window.innerWidth) {\n          gsap.set(flake, { x: window.innerWidth * Math.random() });\n        }\n      });\n    });\n  }\n}"
  }
}