{
  "id": "scroll-velocity-shader",
  "kind": "element",
  "title": "Scroll velocity shader",
  "summary": "A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.",
  "url": "https://enrichr.dev/elements/scroll-velocity-shader.html",
  "section": "gallery",
  "techniques": [
    "webgl",
    "scroll-driven"
  ],
  "stack": [
    "Vanilla JS",
    "WebGL"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "kinetic",
    "technical"
  ],
  "intents": [
    "scroll velocity image distortion",
    "rgb split on scroll shader",
    "webgl image gallery scroll effect",
    "glitch photos while scrolling",
    "scroll speed shader without three.js"
  ],
  "status": "tested",
  "params": [
    {
      "key": "auto",
      "label": "Autoplay",
      "type": "select",
      "options": [
        [
          "1",
          "On"
        ],
        [
          "0",
          "Off"
        ]
      ],
      "value": "1"
    },
    {
      "key": "strength",
      "label": "Autoplay speed (0 to 1)",
      "type": "range",
      "min": 0.1,
      "max": 1,
      "step": 0.05,
      "value": 0.9
    },
    {
      "key": "distortion",
      "label": "Wave size at full speed",
      "type": "range",
      "min": 0,
      "max": 0.08,
      "step": 0.005,
      "value": 0.03
    },
    {
      "key": "split",
      "label": "Colour split (x)",
      "type": "range",
      "min": 0,
      "max": 3,
      "step": 0.1,
      "value": 1
    },
    {
      "key": "settle",
      "label": "Settle time (s)",
      "type": "range",
      "min": 0.2,
      "max": 2,
      "step": 0.05,
      "value": 0.8
    },
    {
      "key": "wave",
      "label": "Wave speed (x)",
      "type": "range",
      "min": 0,
      "max": 3,
      "step": 0.1,
      "value": 1
    },
    {
      "key": "title",
      "label": "Heading",
      "type": "text",
      "value": "Scroll speed, made visible"
    },
    {
      "key": "text",
      "label": "Intro line",
      "type": "text",
      "value": "Every photo runs its own shader. The faster you scroll, the more it waves and splits into colour, then it settles."
    },
    {
      "key": "background",
      "label": "Background",
      "type": "color",
      "value": "#0c1e18"
    },
    {
      "key": "line",
      "label": "Frame outline",
      "type": "color",
      "value": "#085e3d"
    },
    {
      "key": "ink",
      "label": "Text",
      "type": "color",
      "value": "#fbf8f1"
    }
  ],
  "license": "Free to use in personal and client projects during the preview. Final licence terms will be published here before any paid tier starts; ask before reselling the code as a collection.",
  "contract": "function mount(root, opts) -> { update(partialOpts), destroy() }; root must contain the element markup",
  "exports": {
    "claude": "Add the \"Scroll velocity shader\" element to this project.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSteps:\n1. Look at the project first to see its framework and where components, styles and static files live. Follow its conventions.\n2. Fetch https://enrichr.dev/elements/scroll-velocity-shader.json if you can read URLs (fields: source.markup, source.css, source.js, params); otherwise use the source at the end of this message.\n3. Add the files, mount it where I tell you (default: the top of the home page), and pass the settings below as the opts.\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n5. Run the dev server and check it. with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "chatgpt": "I want the \"Scroll velocity shader\" element on my website. Below is its complete source. Please:\n1. Build one self-contained index.html that I can open locally to see it working (put the CSS in a <style> tag and the JavaScript in a <script> tag, with the markup in the body).\n2. Then explain, step by step, which parts go where in my own site, and how to mount it. My stack is: [tell me yours, or say \"plain HTML\"].\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "cursor": "Add the \"Scroll velocity shader\" element to this codebase.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nUse Composer / agent mode. First search the repo for how components, styles and scripts are organised, then add the files in the matching places, mount it on the page I name, and run the app to confirm it works. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nOptional: save this as .cursor/rules/enrichr-scroll-velocity-shader.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Scroll velocity shader element\nalwaysApply: false\n---\nmount(root, opts) expects the element markup inside root and returns { update, destroy }. Always call destroy() on unmount and never edit the ef- class names.",
    "v0": "Create a Next.js (App Router) client component for the \"Scroll velocity shader\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- scroll-velocity-shader.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nUse this component as the wrapper (adjust the import paths):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./scroll-velocity-shader\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ScrollVelocityShader(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRender it on the home page so I can see it. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "lovable": "Add the \"Scroll velocity shader\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- scroll-velocity-shader.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nWrapper component (src/components/ScrollVelocityShader.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./scroll-velocity-shader\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ScrollVelocityShader(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRemove the \"use client\" line if it is not needed. Show it on the home page. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "bolt": "Create a small Vite project (vanilla JavaScript, no framework unless I already have one) that shows the \"Scroll velocity shader\" element.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, then a script tag), style.css (the CSS below), scroll-velocity-shader.js (the JavaScript below) and main.js that sets the container's innerHTML to the markup and calls mount(container, opts) with the settings below. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "replit": "Create a new HTML, CSS and JavaScript Repl that shows the \"Scroll velocity shader\" element. No packages, no server code.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, link style.css, load scroll-velocity-shader.js and then main.js), style.css (the CSS below), scroll-velocity-shader.js (the JavaScript below), main.js (sets the container's innerHTML to the markup, then calls mount(container, opts) with the settings below). Press Run to preview. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "figma": "Designer handoff notes for the \"Scroll velocity shader\" element (Enrichr Library). Figma cannot run this JavaScript inside a design file, so use it as a motion reference and hand the code to a developer.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nWhat it does: Scroll speed is measured in pixels per second from both the page and the column's own scroller, the way GSAP ScrollTrigger reports it: samples at most every 50 ms, read as zero after half a second without movement. The speed is clamped to 2,000, divided by 1,000 and kept with its direction. If a new reading is stronger than the effect already showing, it takes over and then eases back to zero over 0.8 seconds on a sine in-out curve. A small fragment shader draws each photo with a cover fit worked out in the vertex shader, moves every pixel along a sine and a cosine wave whose size is 0.03 times that strength, and samples red, green and blue at slightly different sideways offsets in the scroll direction, which gives the colour split. One WebGL context draws each photo in turn and copies the result into that photo's own canvas, so the canvases scroll natively and the page never runs out of WebGL contexts. Autoplay glides the column to the next photo every few seconds and feeds in the speed a real scroll that fast would read, so a preview moves without anyone scrolling.\nAccessibility: Each photo canvas has a text label, and the heading and intro are real text. The column is a focusable region, so arrow keys and Page Down scroll it. With prefers-reduced-motion the photos are shown plain, with no shader, no distortion and no autoplay. Autoplay stops while you scroll, touch or hover the column. The distortion only follows your own scrolling and settles in under a second.\n\nTunable settings:\n- Autoplay: select (On / Off), default 1\n- Autoplay speed (0 to 1): range 0.1 to 1, step 0.05, default 0.9\n- Wave size at full speed: range 0 to 0.08, step 0.005, default 0.03\n- Colour split (x): range 0 to 3, step 0.1, default 1\n- Settle time (s): range 0.2 to 2, step 0.05, default 0.8\n- Wave speed (x): range 0 to 3, step 0.1, default 1\n- Heading: text, default Scroll speed, made visible\n- Intro line: text, default Every photo runs its own shader. The faster you scroll, the more it waves and splits into colour, then it settles.\n- Background: color, default #0c1e18\n- Frame outline: color, default #085e3d\n- Text: color, default #fbf8f1\n\nCurrent settings:\n{{SETTINGS}}\n\nFor the developer: Element contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nIn Figma:\n- Draw the resting state as a frame and the end state as a second frame; link them with Smart Animate to show the motion in a prototype.\n- Put the settings above in the frame's notes or Dev Mode annotations so the developer matches them.\n- Link https://enrichr.dev/elements/scroll-velocity-shader.html in the handoff: the live demo and the copy-ready code are there. Developers can paste the prompts for Claude, Cursor or v0 from the Export menu.\nNothing is copied from another designer's file; this is original code from Enrichr.",
    "framer": "Add the \"Scroll velocity shader\" element to Framer as a code component. Framer code components are React, so wrap the vanilla code like this. Check it in the Framer editor, as Framer's component API can change.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. In Framer: Assets > Code > New component. Name it ScrollVelocityShader.\n2. Paste the JavaScript below into a separate code file named scroll-velocity-shader.js in the same project, with  export { mount };  and  export const markup = \"<the markup string>\";  added. Put the CSS into the component as a <style> tag.\n3. Component:\n```tsx\nimport { addPropertyControls, ControlType } from \"framer\"\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./scroll-velocity-shader\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ScrollVelocityShader(props: any) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n\naddPropertyControls(ScrollVelocityShader, {\n  auto: { type: ControlType.Enum, title: \"Autoplay\", options: [\"1\",\"0\"], optionTitles: [\"On\",\"Off\"], defaultValue: \"1\" },\n  strength: { type: ControlType.Number, title: \"Autoplay speed\", min: 0.1, max: 1, step: 0.05, defaultValue: 0.9 },\n  distortion: { type: ControlType.Number, title: \"Wave size at full speed\", min: 0, max: 0.08, step: 0.005, defaultValue: 0.03 },\n  split: { type: ControlType.Number, title: \"Colour split\", min: 0, max: 3, step: 0.1, defaultValue: 1 },\n  settle: { type: ControlType.Number, title: \"Settle time\", min: 0.2, max: 2, step: 0.05, defaultValue: 0.8 },\n  wave: { type: ControlType.Number, title: \"Wave speed\", min: 0, max: 3, step: 0.1, defaultValue: 1 },\n  title: { type: ControlType.String, title: \"Heading\", defaultValue: \"Scroll speed, made visible\" },\n  text: { type: ControlType.String, title: \"Intro line\", defaultValue: \"Every photo runs its own shader. The faster you scroll, the more it waves and splits into colour, then it settles.\" },\n  background: { type: ControlType.Color, title: \"Background\", defaultValue: \"#0c1e18\" },\n  line: { type: ControlType.Color, title: \"Frame outline\", defaultValue: \"#085e3d\" },\n  ink: { type: ControlType.Color, title: \"Text\", defaultValue: \"#fbf8f1\" },\n})\n```\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "webflow": "Add the \"Scroll velocity shader\" element to a Webflow site with an Embed element. Test it on the published or preview site: scripts in embeds may not run inside the Designer canvas.\n\nThis is the \"Scroll velocity shader\" element from the Enrichr Library: A column of photos whose WebGL shader waves the picture and splits its colours the faster you scroll, then settles back.\nPage: https://enrichr.dev/elements/scroll-velocity-shader.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-velocity-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. Add an Embed element where it should appear. Paste a <style> block with the CSS, one container <div id=\"enrichr-scroll-velocity-shader\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-scroll-velocity-shader\"), { ...your settings... });\n   (set the container's innerHTML to the markup first, as in the contract).\n2. Embed elements have a size limit (check Webflow's current number). If the code is longer, host the JS and CSS as files and link them from Custom code in the page settings, then keep only the container and the mount call in the Embed.\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}"
  },
  "exportTools": [
    "claude",
    "chatgpt",
    "cursor",
    "v0",
    "lovable",
    "bolt",
    "replit",
    "figma",
    "framer",
    "webflow"
  ],
  "accessibility": "Each photo canvas has a text label, and the heading and intro are real text. The column is a focusable region, so arrow keys and Page Down scroll it. With prefers-reduced-motion the photos are shown plain, with no shader, no distortion and no autoplay. Autoplay stops while you scroll, touch or hover the column. The distortion only follows your own scrolling and settles in under a second.",
  "performance": "There is one WebGL context however many photos there are, and each photo is drawn only while it is near the visible part of the column and the effect is moving; once it settles to zero nothing is redrawn. Photos are uploaded once as 1024 px power-of-two textures with mipmaps, the pixel ratio is capped at 2, and everything pauses off screen and in hidden tabs. On destroy the textures, buffer and program are deleted and the context is released.",
  "dependencies": [],
  "codepen": "https://codepen.io/Enrichr-Dev/pen/rayorgW",
  "source": {
    "markup": "<div class=\"ef-svs\">\n  <div class=\"ef-svs__scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Photo column. Scroll it to bend the photos\">\n    <header class=\"ef-svs__head\">\n      <h3 class=\"ef-svs__title\">Scroll speed, made visible</h3>\n      <p class=\"ef-svs__text\">Every photo runs its own shader. The faster you scroll, the more it waves and splits into colour, then it settles.</p>\n    </header>\n    <div class=\"ef-svs__frame\" data-img=\"/img/library/corgi-4.jpg\"><canvas class=\"ef-svs__c\" role=\"img\" aria-label=\"A corgi and a terrier running down a dirt road\"></canvas></div>\n    <div class=\"ef-svs__frame\" data-img=\"/img/library/corgi-1.jpg\"><canvas class=\"ef-svs__c\" role=\"img\" aria-label=\"Corgi puppy in front of an orange wall\"></canvas></div>\n    <div class=\"ef-svs__frame\" data-img=\"/img/library/corgi-5.jpg\"><canvas class=\"ef-svs__c\" role=\"img\" aria-label=\"Corgi lying down on a white background\"></canvas></div>\n    <div class=\"ef-svs__frame\" data-img=\"/img/library/corgi-2.jpg\"><canvas class=\"ef-svs__c\" role=\"img\" aria-label=\"Corgi sitting in a field of flowers\"></canvas></div>\n    <div class=\"ef-svs__frame\" data-img=\"/img/library/corgi-6.jpg\"><canvas class=\"ef-svs__c\" role=\"img\" aria-label=\"Corgi standing on a white background\"></canvas></div>\n    <div class=\"ef-svs__frame\" data-img=\"/img/library/corgi-3.jpg\"><canvas class=\"ef-svs__c\" role=\"img\" aria-label=\"Corgi standing on a rock among autumn leaves\"></canvas></div>\n    <div class=\"ef-svs__spacer\"></div>\n  </div>\n</div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-svs { --ef-svs-bg: #0c1e18; --ef-svs-line: #085e3d; --ef-svs-ink: #fbf8f1; --ef-svs-acc: #e6ff55; position: relative; width: 100%; min-height: 28rem; overflow: hidden; border-radius: 1rem; background: var(--ef-svs-bg); color: var(--ef-svs-ink); --ef-svs-w: 800px; --ef-svs-h: 28rem; }\n.ef-svs .ef-svs__scroll { position: absolute; inset: 0; overflow-x: hidden; overflow-y: auto; outline: none; scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--ef-svs-ink) 25%, transparent) transparent; }\n.ef-svs .ef-svs__scroll:focus-visible { box-shadow: inset 0 0 0 3px var(--ef-svs-acc); border-radius: 1rem; }\n.ef-svs .ef-svs__head { box-sizing: border-box; min-height: calc(var(--ef-svs-h) * 0.5); padding: 2rem 8% 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }\n.ef-svs .ef-svs__title { margin: 0; max-width: 18ch; font-family: 'Parkinsans', 'Space Grotesk', sans-serif; font-size: clamp(1.5rem, calc(var(--ef-svs-w) * 0.06), 4rem); font-weight: 500; line-height: 1.05; letter-spacing: -0.02em; color: var(--ef-svs-ink); opacity: 1; }\n.ef-svs .ef-svs__text { margin: 1.1rem 0 0; max-width: 36rem; font-family: 'Instrument Sans', system-ui, sans-serif; font-size: clamp(0.85rem, calc(var(--ef-svs-w) * 0.016), 1.1rem); line-height: 1.5; color: var(--ef-svs-ink); opacity: 0.78; }\n.ef-svs .ef-svs__frame { position: relative; box-sizing: border-box; width: 80%; max-width: 600px; aspect-ratio: 16 / 9; margin: calc(var(--ef-svs-h) * 0.2) auto; padding: 0.5rem; border-radius: 10px; outline: dashed 2px var(--ef-svs-line); background-color: transparent; background-repeat: no-repeat; background-position: center; background-size: cover; background-origin: content-box; background-clip: content-box; }\n.ef-svs .ef-svs__c { position: absolute; inset: 0.5rem; display: block; width: calc(100% - 1rem); height: calc(100% - 1rem); }\n.ef-svs .ef-svs__spacer { height: calc(var(--ef-svs-h) * 0.1); }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Scroll velocity shader: a column of photos, each drawn by a small WebGL fragment shader that bends the picture and splits\n// its red, green and blue apart in proportion to how fast you scroll. Scroll speed is read from the page and from the\n// column's own scroller, in px/s, clamped to 2,000 and divided by 1,000. When a reading is stronger than the effect already\n// showing, it takes over and then eases back to zero over 0.8 s on a sine in-out curve, the same rule as the original GSAP\n// ScrollTrigger version. The shader pushes each pixel along a sine and a cosine wave whose size is 0.03 x that strength and\n// shifts the three colour channels sideways by different amounts, in the scroll direction. One WebGL context draws every\n// frame and copies it to that photo's own canvas, so the canvases scroll natively with the page and no browser context limit\n// is hit. Autoplay glides the column to the next photo every few seconds and feeds the matching scroll speed in, so a preview\n// moves on its own; it stops while you scroll, touch or hover the column. Reduced motion shows the plain photos and no\n// autoplay. Without WebGL the photos stay as CSS backgrounds. Drawing stops off screen, in hidden tabs, and whenever the\n// effect has settled to zero.\n// mount(root, { auto (\"1\" glide on its own, \"0\" off), strength (autoplay speed, 0-1), distortion (wave size at full speed),\n//               split (colour split, x), settle (s back to rest), wave (wave speed, x), title, text, background, line, ink })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var box = root.querySelector(\".ef-svs\");\n  var scroller = root.querySelector(\".ef-svs__scroll\");\n  var titleEl = root.querySelector(\".ef-svs__title\");\n  var textEl = root.querySelector(\".ef-svs__text\");\n  var frames = Array.prototype.slice.call(root.querySelectorAll(\".ef-svs__frame\")).map(function (el) {\n    return { el: el, c: el.querySelector(\".ef-svs__c\"), ctx: null, url: el.getAttribute(\"data-img\") || \"\", tex: null, iw: 1, ih: 1, w: 0, h: 0, seen: false, dirty: true };\n  });\n  var opts = {}, raf = 0, last = 0, clock = 0, visible = true, destroyed = false, offs = [], io = null, fio = null, ro = null;\n  var vp = { v: 0, s: 0 }, tw = null; // shared velocity proxy: v signed (-1..1), s strength (0..1), tw = the ease back to rest\n  var glc = null, gl = null, prog = null, buf = null, u = {}, ok = false, cache = {};\n  var hold = 0, glide = null, nextAt = 0, autoIdx = -1;\n\n  function num(v, d) { v = Number(v); return isFinite(v) ? v : d; }\n  function now() { return performance.now(); }\n\n  // ---- velocity: ScrollTrigger-style tracker (samples at most every 50 ms, reads zero after 500 ms without movement)\n  function tracker(read) {\n    var v1 = read(), v2 = v1, t1 = now(), t2 = t1;\n    return {\n      update: function () {\n        var t = now(), val = read();\n        if (val === v1) return;\n        if (t - t1 > 50) { v2 = v1; v1 = val; t2 = t1; t1 = t; } else { v1 = v2 + (val - v2) / (t - t2) * (t1 - t2); }\n      },\n      velocity: function () {\n        var t = now();\n        return (t1 === t2 || t - t2 > 500) ? 0 : (v1 - v2) / (t1 - t2) * 1000;\n      }\n    };\n  }\n  var pageV = tracker(function () { return window.scrollY || window.pageYOffset || 0; });\n  var colV = tracker(function () { return scroller.scrollTop; });\n  // the original's ScrollTrigger onUpdate: a stronger reading takes over, then tweens back to 0 (sine.inOut, overwrite)\n  function feed(raw) {\n    raw = Math.max(-2000, Math.min(2000, raw));\n    var norm = raw / 1000, strength = Math.min(1, Math.abs(norm));\n    if (strength > Math.abs(vp.s)) { vp.v = norm; vp.s = strength; tw = { v: norm, s: strength, t: now() }; }\n  }\n  function settle(t) {\n    if (!tw) return;\n    var p = Math.min(1, (t - tw.t) / (opts.settle * 1000)), e = (1 - Math.cos(Math.PI * p)) / 2;\n    vp.v = tw.v * (1 - e); vp.s = tw.s * (1 - e);\n    if (p >= 1) { tw = null; vp.v = 0; vp.s = 0; frames.forEach(function (f) { f.dirty = true; }); }\n  }\n\n  // ---- WebGL: one context, a full-screen triangle, cover-fit UVs worked out in the vertex shader like the original\n  var VS = \"attribute vec2 p;uniform vec2 uTS,uQS;varying vec2 vC;\" +\n    \"void main(){vec2 uv=p*.5+.5;float tr=uTS.x/uTS.y,qr=uQS.x/uQS.y;vec2 s=vec2(1.);if(qr>tr){s.y=tr/qr;}else{s.x=qr/tr;}\" +\n    \"vC=uv*s+(1.-s)*.5;gl_Position=vec4(p,0.,1.);}\";\n  var FS = \"#ifdef GL_FRAGMENT_PRECISION_HIGH\\nprecision highp float;\\n#else\\nprecision mediump float;\\n#endif\\n\" +\n    \"uniform sampler2D uT;uniform float uTime,uV,uS,uAmt,uSplit;varying vec2 vC;\" +\n    \"void main(){vec2 tc=vC;float amt=uAmt*uS;float t=uTime*.8;\" +\n    \"tc.y+=sin((tc.x*8.)+t)*amt;tc.x+=cos((tc.y*6.)-t*.8)*amt*.6;\" +\n    \"float d=sign(uV)*uSplit;\" +\n    \"float r=texture2D(uT,tc+vec2(amt*.5*d,0.)).r;float g=texture2D(uT,tc+vec2(amt*.25*d,0.)).g;float b=texture2D(uT,tc+vec2(-amt*.35*d,0.)).b;\" +\n    \"gl_FragColor=vec4(r,g,b,1.);}\";\n  function sh(type, src) { var s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return gl.getShaderParameter(s, gl.COMPILE_STATUS) ? s : null; }\n  function setup() {\n    glc = document.createElement(\"canvas\");\n    try { gl = glc.getContext(\"webgl\", { antialias: false, alpha: false, depth: false, powerPreference: \"low-power\" }); } catch (e) { gl = null; }\n    if (!gl) return false;\n    var v = sh(gl.VERTEX_SHADER, VS), f = sh(gl.FRAGMENT_SHADER, FS);\n    if (!v || !f) return false;\n    prog = gl.createProgram(); gl.attachShader(prog, v); gl.attachShader(prog, f); gl.linkProgram(prog);\n    gl.deleteShader(v); gl.deleteShader(f);\n    if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) return false;\n    gl.useProgram(prog);\n    buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n    var loc = gl.getAttribLocation(prog, \"p\"); gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);\n    [\"uTS\", \"uQS\", \"uT\", \"uTime\", \"uV\", \"uS\", \"uAmt\", \"uSplit\"].forEach(function (k) { u[k] = gl.getUniformLocation(prog, k); });\n    gl.uniform1i(u.uT, 0);\n    return true;\n  }\n  // power-of-two copy of the photo so it can have mipmaps (smooth when shrunk); the true size goes to the cover maths\n  function upload(img) {\n    var tex = gl.createTexture(), side = 1024, c = document.createElement(\"canvas\");\n    c.width = c.height = side; c.getContext(\"2d\").drawImage(img, 0, 0, side, side);\n    gl.bindTexture(gl.TEXTURE_2D, tex);\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);\n    gl.generateMipmap(gl.TEXTURE_2D);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n    return tex;\n  }\n  function load(f) {\n    if (!f.url) return;\n    var hit = cache[f.url];\n    function done(entry, g) { g.tex = entry.tex; g.iw = entry.w; g.ih = entry.h; g.dirty = true; }\n    if (hit && hit.tex) { done(hit, f); return; }\n    if (hit) { hit.wait.push(f); return; }\n    hit = cache[f.url] = { tex: null, w: 1, h: 1, wait: [f] };\n    var img = new Image(); img.crossOrigin = \"anonymous\"; img.decoding = \"async\";\n    img.onload = function () {\n      if (destroyed || !gl) return;\n      try { hit.tex = upload(img); } catch (e) { return; } // a remote photo without CORS: the CSS background stays\n      hit.w = img.naturalWidth || 1; hit.h = img.naturalHeight || 1;\n      hit.wait.forEach(function (g) { done(hit, g); }); hit.wait = [];\n    };\n    img.src = f.url;\n  }\n  // the column is laid out in units of the box (the original used the viewport): 20% of its height between photos\n  function sizeBox() {\n    box.style.setProperty(\"--ef-svs-w\", Math.max(1, box.clientWidth) + \"px\");\n    box.style.setProperty(\"--ef-svs-h\", Math.max(1, box.clientHeight) + \"px\");\n  }\n  function sizeFrames() {\n    var dpr = Math.min(window.devicePixelRatio || 1, 2);\n    frames.forEach(function (f) {\n      var w = Math.max(1, Math.round(f.c.clientWidth * dpr)), h = Math.max(1, Math.round(f.c.clientHeight * dpr));\n      if (w !== f.w || h !== f.h) { f.w = w; f.h = h; f.c.width = w; f.c.height = h; f.dirty = true; }\n    });\n  }\n  function draw(f) {\n    if (glc.width !== f.w || glc.height !== f.h) { glc.width = f.w; glc.height = f.h; }\n    gl.viewport(0, 0, f.w, f.h);\n    gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, f.tex);\n    gl.uniform2f(u.uTS, f.iw, f.ih); gl.uniform2f(u.uQS, f.w, f.h);\n    gl.uniform1f(u.uTime, clock); gl.uniform1f(u.uV, vp.v); gl.uniform1f(u.uS, vp.s);\n    gl.uniform1f(u.uAmt, opts.distortion); gl.uniform1f(u.uSplit, opts.split);\n    gl.drawArrays(gl.TRIANGLES, 0, 3);\n    if (!f.ctx) f.ctx = f.c.getContext(\"2d\");\n    f.ctx.clearRect(0, 0, f.w, f.h);\n    f.ctx.drawImage(glc, 0, 0);\n    f.dirty = false;\n  }\n\n  // ---- autoplay: glide the column to the next photo and feed in the speed a real scroll that fast would read\n  function autoOn() { return !reduce && String(opts.auto) !== \"0\"; }\n  function target(i) { var f = frames[i].el; return Math.max(0, Math.min(scroller.scrollHeight - scroller.clientHeight, f.offsetTop - (scroller.clientHeight - f.offsetHeight) / 2)); }\n  function startGlide(t) {\n    autoIdx = (autoIdx + 1) % frames.length;\n    var from = scroller.scrollTop, to = target(autoIdx);\n    if (Math.abs(to - from) < 2) { nextAt = t + 2600; return; }\n    glide = { from: from, to: to, t: t, d: autoIdx === 0 ? 1400 : 900 };\n  }\n  function stepGlide(t) {\n    var p = Math.min(1, (t - glide.t) / glide.d);\n    var e = p < 0.5 ? 4 * p * p * p : 1 - Math.pow(-2 * p + 2, 3) / 2; // power2.inOut\n    var de = p < 0.5 ? 12 * p * p : 3 * Math.pow(-2 * p + 2, 2);       // its slope, 3 at the middle\n    scroller.scrollTop = glide.from + (glide.to - glide.from) * e;\n    feed((glide.to > glide.from ? 1 : -1) * opts.strength * 1000 * de / 3);\n    if (p >= 1) { glide = null; nextAt = t + 2600; }\n  }\n  function pause(ms) { hold = Math.max(hold, now() + ms); glide = null; }\n\n  function loop(t) {\n    raf = requestAnimationFrame(loop);\n    var dt = Math.min(0.05, (t - last) / 1000 || 0); last = t;\n    if (!visible || document.hidden) return;\n    clock = (clock + dt * opts.wave) % 39.2699; // both waves repeat every 2 PI / 0.16 s, so wrapping keeps float precision\n    if (autoOn() && t > hold) {\n      if (glide) stepGlide(t);\n      else if (!nextAt) nextAt = t + 1200;\n      else if (t >= nextAt) startGlide(t);\n    }\n    settle(t);\n    if (!ok) return;\n    var moving = vp.s > 0;\n    for (var i = 0; i < frames.length; i++) {\n      var f = frames[i];\n      if (f.seen && f.tex && (moving || f.dirty)) draw(f);\n    }\n  }\n\n  function on(el, type, fn, opt) { el.addEventListener(type, fn, opt); offs.push(function () { el.removeEventListener(type, fn, opt); }); }\n  function onPageScroll() { if (visible) { pageV.update(); feed(pageV.velocity()); } }\n  function onColScroll() { colV.update(); if (!glide) feed(colV.velocity()); }\n  function onUser() { pause(3000); }\n\n  function update(next) {\n    opts = Object.assign({ auto: \"1\", strength: 0.9, distortion: 0.03, split: 1, settle: 0.8, wave: 1, title: \"Scroll speed, made visible\", text: \"Every photo runs its own shader. The faster you scroll, the more it waves and splits into colour, then it settles.\", background: \"#0c1e18\", line: \"#085e3d\", ink: \"#fbf8f1\" }, opts, next || {});\n    opts.strength = Math.max(0, Math.min(1, num(opts.strength, 0.9))); opts.distortion = Math.max(0, num(opts.distortion, 0.03));\n    opts.split = num(opts.split, 1); opts.settle = Math.max(0.05, num(opts.settle, 0.8)); opts.wave = Math.max(0, num(opts.wave, 1));\n    box.style.setProperty(\"--ef-svs-bg\", opts.background);\n    box.style.setProperty(\"--ef-svs-line\", opts.line);\n    box.style.setProperty(\"--ef-svs-ink\", opts.ink);\n    titleEl.textContent = opts.title; textEl.textContent = opts.text;\n    titleEl.hidden = !opts.title; textEl.hidden = !opts.text;\n    if (!autoOn()) glide = null;\n    frames.forEach(function (f) { f.dirty = true; });\n  }\n\n  frames.forEach(function (f) { if (f.url) f.el.style.backgroundImage = \"url(\\\"\" + f.url.replace(/\"/g, \"%22\") + \"\\\")\"; });\n  sizeBox();\n  update(o);\n  ok = !reduce && setup();\n  if (!ok) frames.forEach(function (f) { f.c.style.display = \"none\"; });\n  if (ok) {\n    frames.forEach(load);\n    sizeFrames();\n    if (\"IntersectionObserver\" in window) {\n      io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(box);\n      fio = new IntersectionObserver(function (es) { es.forEach(function (e) { for (var i = 0; i < frames.length; i++) if (frames[i].el === e.target) frames[i].seen = e.isIntersecting; }); }, { root: scroller, rootMargin: \"60px 0px\" });\n      frames.forEach(function (f) { fio.observe(f.el); });\n    } else frames.forEach(function (f) { f.seen = true; });\n  }\n  if (\"ResizeObserver\" in window) { ro = new ResizeObserver(function () { if (destroyed) return; sizeBox(); if (ok) sizeFrames(); }); ro.observe(box); }\n  if (ok) {\n    on(window, \"scroll\", onPageScroll, { passive: true });\n    on(scroller, \"scroll\", onColScroll, { passive: true });\n    [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"].forEach(function (t) { on(scroller, t, onUser, { passive: true }); });\n    on(scroller, \"pointerenter\", function (e) { if (e.pointerType === \"mouse\") pause(1e9); });\n    on(scroller, \"pointerleave\", function (e) { if (e.pointerType === \"mouse\") { hold = now() + 1500; nextAt = 0; } });\n    last = now(); raf = requestAnimationFrame(loop);\n  }\n  return {\n    update: update,\n    destroy: function () {\n      destroyed = true; cancelAnimationFrame(raf);\n      offs.forEach(function (f) { f(); }); offs = [];\n      if (io) io.disconnect();\n      if (fio) fio.disconnect();\n      if (ro) ro.disconnect();\n      if (gl) {\n        Object.keys(cache).forEach(function (k) { if (cache[k].tex) gl.deleteTexture(cache[k].tex); });\n        if (buf) gl.deleteBuffer(buf);\n        if (prog) gl.deleteProgram(prog);\n        var lose = gl.getExtension(\"WEBGL_lose_context\"); if (lose) lose.loseContext();\n      }\n      cache = {}; gl = null;\n    }\n  };\n}"
  }
}