{
  "id": "horizontal-scroll-colour-morph",
  "kind": "element",
  "title": "Horizontal scroll colour morph",
  "summary": "A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.",
  "url": "https://enrichr.dev/elements/horizontal-scroll-colour-morph.html",
  "section": "page",
  "techniques": [
    "scroll-driven",
    "text-animation"
  ],
  "stack": [
    "Vanilla JS",
    "CSS"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "bold",
    "kinetic"
  ],
  "intents": [
    "horizontal scroll text pinned section",
    "background colour change on scroll",
    "scroll driven colour morph",
    "letters tumble in on horizontal scroll",
    "gsap horizontal scroll without gsap"
  ],
  "status": "tested",
  "params": [
    {
      "key": "theme",
      "label": "Colour theme",
      "type": "select",
      "options": [
        [
          "enrichr",
          "Enrichr (ink to green)"
        ],
        [
          "day-to-night",
          "Day to night"
        ],
        [
          "cyberpunk",
          "Neon pink to cyan"
        ],
        [
          "emerald",
          "Deep slate to emerald"
        ],
        [
          "custom",
          "Custom (colours below)"
        ]
      ],
      "value": "enrichr"
    },
    {
      "key": "text",
      "label": "Line of text",
      "type": "text",
      "value": "Design Bold. Ship Fast."
    },
    {
      "key": "length",
      "label": "Scroll length (x box width)",
      "type": "range",
      "min": 1,
      "max": 5,
      "step": 0.1,
      "value": 2.7
    },
    {
      "key": "auto",
      "label": "Autoplay",
      "type": "select",
      "options": [
        [
          "1",
          "On"
        ],
        [
          "0",
          "Off"
        ]
      ],
      "value": "1"
    },
    {
      "key": "bgFrom",
      "label": "Custom background, start",
      "type": "color",
      "value": "#fbf8f1"
    },
    {
      "key": "bgTo",
      "label": "Custom background, end",
      "type": "color",
      "value": "#e6ff55"
    },
    {
      "key": "textFrom",
      "label": "Custom text, start",
      "type": "color",
      "value": "#0c1e18"
    },
    {
      "key": "textTo",
      "label": "Custom text, end",
      "type": "color",
      "value": "#005236"
    },
    {
      "key": "accent",
      "label": "Progress bar and hint",
      "type": "color",
      "value": "#e6ff55"
    }
  ],
  "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 \"Horizontal scroll colour morph\" element to this project.\n\nThis is the \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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/horizontal-scroll-colour-morph.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 \"Horizontal scroll colour morph\" 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 \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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 \"Horizontal scroll colour morph\" element to this codebase.\n\nThis is the \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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-horizontal-scroll-colour-morph.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Horizontal scroll colour morph 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 \"Horizontal scroll colour morph\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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- horizontal-scroll-colour-morph.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 \"./horizontal-scroll-colour-morph\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function HorizontalScrollColourMorph(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 \"Horizontal scroll colour morph\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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- horizontal-scroll-colour-morph.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/HorizontalScrollColourMorph.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./horizontal-scroll-colour-morph\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function HorizontalScrollColourMorph(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 \"Horizontal scroll colour morph\" element.\n\nThis is the \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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), horizontal-scroll-colour-morph.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 \"Horizontal scroll colour morph\" element. No packages, no server code.\n\nThis is the \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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 horizontal-scroll-colour-morph.js and then main.js), style.css (the CSS below), horizontal-scroll-colour-morph.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 \"Horizontal scroll colour morph\" 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 \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.json\n\nWhat it does: The band has its own scroller. Inside it a sticky stage stays put while a track 2.7 box widths taller scrolls past, which is the same as pinning a section for about 3,500 px on a laptop screen. Scroll progress from 0 to 1 drives three things, as in the GSAP ScrollTrigger original. The line of type moves left by its own full width, and starts one box width to the right, so it enters from the right edge and leaves on the left. The background and type colours are mixed between the theme's start and end colours exactly at the current progress, and a thin bar fills along the top. Each letter is wrapped in its own span and tumbles in from a random height between -200% and 20% and a random tilt of up to 25 degrees, with a back.out(1.2) ease, over the stretch of scroll where its left edge travels from the right edge of the box to 30% across. The line follows the scroll with 0.5 seconds of smoothing and the letters with 1 second, done the way ScrollTrigger's scrub does it: on every scroll update an expo.out tween restarts from where the value is now toward the new progress. Seventy faint stars twinkle on a canvas behind. Autoplay scrolls the band forward, pauses, and comes back, so a preview moves without anyone scrolling.\nAccessibility: The heading keeps the whole line as its accessible name and the letter spans are hidden from screen readers. The scroller is a focusable region, so arrow keys, Page Down and the space bar drive it, and it shows a lime focus ring. With prefers-reduced-motion there is no scroll run, no tumbling and no autoplay: the line is wrapped and centred over a still gradient of the two background colours. Autoplay stops as soon as you scroll, touch, press a key or hover the band. Check text contrast at both ends when you pick custom colours.\n\nTunable settings:\n- Colour theme: select (Enrichr (ink to green) / Day to night / Neon pink to cyan / Deep slate to emerald / Custom (colours below)), default enrichr\n- Line of text: text, default Design Bold. Ship Fast.\n- Scroll length (x box width): range 1 to 5, step 0.1, default 2.7\n- Autoplay: select (On / Off), default 1\n- Custom background, start: color, default #fbf8f1\n- Custom background, end: color, default #e6ff55\n- Custom text, start: color, default #0c1e18\n- Custom text, end: color, default #005236\n- Progress bar and hint: color, default #e6ff55\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/horizontal-scroll-colour-morph.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 \"Horizontal scroll colour morph\" 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 \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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 HorizontalScrollColourMorph.\n2. Paste the JavaScript below into a separate code file named horizontal-scroll-colour-morph.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 \"./horizontal-scroll-colour-morph\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function HorizontalScrollColourMorph(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(HorizontalScrollColourMorph, {\n  theme: { type: ControlType.Enum, title: \"Colour theme\", options: [\"enrichr\",\"day-to-night\",\"cyberpunk\",\"emerald\",\"custom\"], optionTitles: [\"Enrichr (ink to green)\",\"Day to night\",\"Neon pink to cyan\",\"Deep slate to emerald\",\"Custom (colours below)\"], defaultValue: \"enrichr\" },\n  text: { type: ControlType.String, title: \"Line of text\", defaultValue: \"Design Bold. Ship Fast.\" },\n  length: { type: ControlType.Number, title: \"Scroll length\", min: 1, max: 5, step: 0.1, defaultValue: 2.7 },\n  auto: { type: ControlType.Enum, title: \"Autoplay\", options: [\"1\",\"0\"], optionTitles: [\"On\",\"Off\"], defaultValue: \"1\" },\n  bgFrom: { type: ControlType.Color, title: \"Custom background, start\", defaultValue: \"#fbf8f1\" },\n  bgTo: { type: ControlType.Color, title: \"Custom background, end\", defaultValue: \"#e6ff55\" },\n  textFrom: { type: ControlType.Color, title: \"Custom text, start\", defaultValue: \"#0c1e18\" },\n  textTo: { type: ControlType.Color, title: \"Custom text, end\", defaultValue: \"#005236\" },\n  accent: { type: ControlType.Color, title: \"Progress bar and hint\", defaultValue: \"#e6ff55\" },\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 \"Horizontal scroll colour morph\" 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 \"Horizontal scroll colour morph\" element from the Enrichr Library: A pinned band where scrolling slides one huge line of type sideways, tumbles each letter into place and morphs the background from one colour to another.\nPage: https://enrichr.dev/elements/horizontal-scroll-colour-morph.html\nMachine-readable spec: https://enrichr.dev/elements/horizontal-scroll-colour-morph.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-horizontal-scroll-colour-morph\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-horizontal-scroll-colour-morph\"), { ...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": "The heading keeps the whole line as its accessible name and the letter spans are hidden from screen readers. The scroller is a focusable region, so arrow keys, Page Down and the space bar drive it, and it shows a lime focus ring. With prefers-reduced-motion there is no scroll run, no tumbling and no autoplay: the line is wrapped and centred over a still gradient of the two background colours. Autoplay stops as soon as you scroll, touch, press a key or hover the band. Check text contrast at both ends when you pick custom colours.",
  "performance": "Only transforms, opacity and two colours change per frame, so there is no layout work while scrolling. Letter positions are measured once, and again only after a resize or when fonts finish loading. A letter's style is written only when its value actually changes. The star canvas uses the box size with the pixel ratio capped at 2, and the whole loop pauses off screen and in hidden tabs.",
  "dependencies": [],
  "codepen": "https://codepen.io/Enrichr-Dev/pen/MYpZBza",
  "source": {
    "markup": "<div class=\"ef-hcm\">\n  <div class=\"ef-hcm__scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scroll inside this panel to slide the words sideways and morph the colour\">\n    <div class=\"ef-hcm__track\">\n      <div class=\"ef-hcm__stage\">\n        <canvas class=\"ef-hcm__stars\" aria-hidden=\"true\"></canvas>\n        <div class=\"ef-hcm__wrap\">\n          <h3 class=\"ef-hcm__text\">Design Bold. Ship Fast.</h3>\n        </div>\n        <p class=\"ef-hcm__hint\">Scroll to morph the colour</p>\n      </div>\n    </div>\n  </div>\n  <div class=\"ef-hcm__bar\" aria-hidden=\"true\"></div>\n</div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-hcm { --ef-hcm-w: 1280px; --ef-hcm-h: 26rem; --ef-hcm-run: 0px; --ef-hcm-acc: #e6ff55; --ef-hcm-bg: #0c1e18; position: relative; width: 100%; min-height: 26rem; overflow: hidden; border-radius: 1rem; background: var(--ef-hcm-bg); color: #fbf8f1; }\n.ef-hcm .ef-hcm__scroll { position: absolute; inset: 0; overflow-x: hidden; overflow-y: auto; outline: none; scrollbar-width: none; }\n.ef-hcm .ef-hcm__scroll::-webkit-scrollbar { display: none; }\n.ef-hcm .ef-hcm__scroll:focus-visible .ef-hcm__stage { box-shadow: inset 0 0 0 3px var(--ef-hcm-acc); }\n.ef-hcm .ef-hcm__track { position: relative; height: calc(var(--ef-hcm-h) + var(--ef-hcm-run)); }\n.ef-hcm .ef-hcm__stage { position: sticky; top: 0; height: var(--ef-hcm-h); overflow: hidden; display: flex; align-items: center; background-color: var(--ef-hcm-bg); transition: background-color 0.1s linear; will-change: background-color; }\n.ef-hcm .ef-hcm__stars { position: absolute; inset: 0; display: block; width: 100%; height: 100%; pointer-events: none; opacity: 0.5; }\n.ef-hcm .ef-hcm__wrap { position: relative; width: 100%; }\n.ef-hcm .ef-hcm__text { position: relative; display: flex; width: max-content; box-sizing: content-box; margin: 0; padding: 0 calc(var(--ef-hcm-w) * 0.2) 0 var(--ef-hcm-w); gap: calc(var(--ef-hcm-w) * 0.04); white-space: nowrap; font-family: 'Parkinsans', 'Space Grotesk', sans-serif; font-size: clamp(3rem, calc(var(--ef-hcm-w) * 0.12), 13rem); font-weight: 800; line-height: 1; letter-spacing: -0.04em; color: #fbf8f1; opacity: 1; text-transform: none; text-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); transition: color 0.1s linear; will-change: transform; }\n.ef-hcm .ef-hcm__word, .ef-hcm .ef-hcm__space { display: inline-block; white-space: nowrap; }\n.ef-hcm .ef-hcm__char { display: inline-block; will-change: transform; }\n.ef-hcm .ef-hcm__hint { position: absolute; left: 50%; bottom: 1.1rem; z-index: 2; margin: 0; padding: 0.35rem 0.95rem; border-radius: 2rem; transform: translateX(-50%); white-space: nowrap; font-family: 'Instrument Sans', system-ui, sans-serif; font-size: 0.8rem; font-weight: 500; line-height: 1.3; color: var(--ef-hcm-acc); opacity: 1; background: rgba(5, 13, 10, 0.55); border: 1px solid color-mix(in srgb, var(--ef-hcm-acc) 35%, transparent); transition: opacity 0.3s ease; pointer-events: none; }\n.ef-hcm .ef-hcm__bar { position: absolute; top: 0; left: 0; z-index: 3; width: 0; height: 4px; background: linear-gradient(90deg, #1a7a4c, var(--ef-hcm-acc)); transition: width 0.05s linear; pointer-events: none; }\n.ef-hcm.ef-hcm--calm .ef-hcm__text { flex-wrap: wrap; justify-content: center; width: auto; padding: 0 6%; gap: 0 0.08em; white-space: normal; text-align: center; font-size: clamp(2.2rem, calc(var(--ef-hcm-w) * 0.09), 9rem); transform: none; }\n.ef-hcm.ef-hcm--calm .ef-hcm__hint, .ef-hcm.ef-hcm--calm .ef-hcm__bar { display: none; }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Horizontal scroll colour morph: a pinned band where scrolling down slides one huge line of type sideways while the\n// background and the type colour morph from one theme colour to the other. The band sticks inside its own scroller for a\n// run of 2.7 box widths (about the original's 3,500 px on a laptop). Scroll progress drives three things, as in the original\n// GSAP ScrollTrigger version: the line moves left by its full width with 0.5 s of scrub smoothing; the colours follow\n// progress exactly; and each letter tumbles in from a random height (-200% to 20%) and tilt (-25 to 25 deg) with a\n// back.out(1.2) ease while its left edge travels from the right edge of the box to 30% across, with 1 s of smoothing.\n// Scrub smoothing restarts an expo.out tween toward the new progress on every scroll update, like ScrollTrigger's scrub.\n// Seventy faint stars twinkle behind. Autoplay scrolls the band on its own (forward, pause, back) until someone scrolls,\n// touches or hovers it. Reduced motion shows one still frame: the line wrapped and centred over a gradient of the two\n// background colours, no tumbling and no autoplay. The animation pauses off screen and in hidden tabs.\n// mount(root, { theme (\"enrichr\", \"day-to-night\", \"cyberpunk\", \"emerald\", \"custom\"), text, length (scroll run, x box width),\n//               auto (\"1\" on, \"0\" off), bgFrom, bgTo, textFrom, textTo (used by the custom theme), accent (progress bar, hint) })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var box = root.querySelector(\".ef-hcm\");\n  var scroller = root.querySelector(\".ef-hcm__scroll\");\n  var stage = root.querySelector(\".ef-hcm__stage\");\n  var canvas = root.querySelector(\".ef-hcm__stars\");\n  var textEl = root.querySelector(\".ef-hcm__text\");\n  var hint = root.querySelector(\".ef-hcm__hint\");\n  var bar = root.querySelector(\".ef-hcm__bar\");\n  var ctx = canvas.getContext(\"2d\");\n  var THEMES = {\n    \"enrichr\": [\"#0c1e18\", \"#005236\", \"#fbf8f1\", \"#e6ff55\"],\n    \"day-to-night\": [\"#d97706\", \"#020617\", \"#ffffff\", \"#38bdf8\"],\n    \"cyberpunk\": [\"#be185d\", \"#0891b2\", \"#fef08a\", \"#ffffff\"],\n    \"emerald\": [\"#0f172a\", \"#047857\", \"#38bdf8\", \"#a7f3d0\"]\n  };\n  var opts = {}, cols = null, W = 1, H = 1, run = 0, dpr = 1, chars = [], stars = [];\n  var main = { from: 0, to: 0, cur: 0, t: 0 }, P = 0, lastP = -1, lastColP = -1, textW = 1;\n  var raf = 0, last = 0, visible = true, destroyed = false, io = null, ro = null, offs = [], hold = 0, auto = null, lastText = null;\n\n  function num(v, d) { v = Number(v); return isFinite(v) ? v : d; }\n  function now() { return performance.now(); }\n  function hex(h, d) { var m = /^#?([0-9a-f]{6})$/i.exec(h || \"\"); var v = parseInt(m ? m[1] : d, 16); return [v >> 16, (v >> 8) & 255, v & 255]; }\n  function mix(a, b, t) { return \"rgb(\" + Math.round(a[0] + (b[0] - a[0]) * t) + \",\" + Math.round(a[1] + (b[1] - a[1]) * t) + \",\" + Math.round(a[2] + (b[2] - a[2]) * t) + \")\"; }\n  // stable random numbers per letter, so a resize or a colour change keeps the same tumble\n  function rand(i, salt) { var h = Math.imul(i + 1 + salt * 7919, 374761393) ^ Math.imul(salt + 13, 668265263); h = Math.imul(h ^ (h >>> 13), 1274126177); return ((h ^ (h >>> 16)) >>> 0) / 4294967296; }\n  function backOut(p) { var c = 1.2; p -= 1; return p * p * ((c + 1) * p + c) + 1; } // GSAP back.out(1.2)\n  function expoOut(p) { return p >= 1 ? 1 : 1 - Math.pow(2, -10 * p); }           // ScrollTrigger's scrub ease\n  function sineInOut(p) { return (1 - Math.cos(Math.PI * p)) / 2; }\n\n  // SplitText by hand: words of letters, the full line kept as the heading's accessible name\n  function split() {\n    var text = String(opts.text || \"\").trim() || \"Design Bold. Ship Fast.\";\n    if (text === lastText) return;\n    lastText = text;\n    textEl.textContent = \"\";\n    textEl.setAttribute(\"aria-label\", text);\n    chars = [];\n    text.split(/\\s+/).forEach(function (word, wi, words) {\n      var w = document.createElement(\"span\"); w.className = \"ef-hcm__word\"; w.setAttribute(\"aria-hidden\", \"true\");\n      Array.from(word).forEach(function (ch) {\n        var c = document.createElement(\"span\"); c.className = \"ef-hcm__char\"; c.textContent = ch;\n        var i = chars.length;\n        chars.push({ el: c, y: -200 + rand(i, 1) * 220, r: -25 + rand(i, 2) * 50, x0: 0, ps: 0, pe: 1, from: 0, to: 0, cur: 0, t: 0, drawn: -1 });\n        w.appendChild(c);\n      });\n      textEl.appendChild(w);\n      if (wi < words.length - 1) { var s = document.createElement(\"span\"); s.className = \"ef-hcm__space\"; s.setAttribute(\"aria-hidden\", \"true\"); s.innerHTML = \"&nbsp;\"; textEl.appendChild(s); }\n    });\n  }\n  // where each letter sits in the untransformed line, and the slice of progress over which it tumbles in:\n  // from its left edge at the right edge of the box (\"left 100%\") to its left edge 30% across (\"left 30%\")\n  function measure() {\n    textW = Math.max(1, textEl.offsetWidth);\n    chars.forEach(function (c) {\n      var x = c.el.offsetLeft; // the heading is the offset parent (position: relative)\n      c.ps = (x - W) / textW; c.pe = (x - 0.3 * W) / textW;\n    });\n  }\n  function size() {\n    W = Math.max(1, scroller.clientWidth); H = Math.max(1, box.clientHeight);\n    run = reduce ? 0 : Math.round(opts.length * W);\n    box.style.setProperty(\"--ef-hcm-w\", W + \"px\");\n    box.style.setProperty(\"--ef-hcm-h\", H + \"px\");\n    box.style.setProperty(\"--ef-hcm-run\", run + \"px\");\n    dpr = Math.min(window.devicePixelRatio || 1, 2);\n    canvas.width = Math.round(W * dpr); canvas.height = Math.round(H * dpr);\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    stars = [];\n    for (var i = 0; i < 70; i++) stars.push({ x: Math.random() * W, y: Math.random() * H, r: Math.random() * 1.5 + 0.5, a: Math.random(), s: Math.random() * 0.02 + 0.005 });\n    measure();\n    lastP = -1; lastColP = -1;\n    drawStars(0);\n  }\n  function drawStars(dt) {\n    ctx.clearRect(0, 0, W, H);\n    var k = dt * 60; // the original stepped once per frame at 60 fps\n    for (var i = 0; i < stars.length; i++) {\n      var s = stars[i];\n      s.a += s.s * k;\n      if (s.a > 1 || s.a < 0) s.s = -s.s;\n      ctx.fillStyle = \"rgba(255,255,255,\" + Math.min(1, Math.abs(s.a)) + \")\";\n      ctx.beginPath(); ctx.arc(s.x, s.y, s.r, 0, Math.PI * 2); ctx.fill();\n    }\n  }\n  function progress() { return run > 0 ? Math.min(1, Math.max(0, scroller.scrollTop / run)) : 0; }\n  function paintColours(p) {\n    if (p === lastColP) return;\n    lastColP = p;\n    stage.style.backgroundColor = mix(cols[0], cols[1], p);\n    textEl.style.color = mix(cols[2], cols[3], p);\n    bar.style.width = (p * 100) + \"%\";\n    hint.style.opacity = p > 0.02 ? \"0\" : \"1\";\n  }\n  function paintLetters(t) {\n    var p = Math.min(1, (t - main.t) / 500);\n    main.cur = main.from + (main.to - main.from) * expoOut(p);\n    textEl.style.transform = \"translate3d(\" + (-100 * main.cur).toFixed(4) + \"%,0,0)\";\n    for (var i = 0; i < chars.length; i++) {\n      var c = chars[i], q = Math.min(1, (t - c.t) / 1000);\n      c.cur = c.from + (c.to - c.from) * expoOut(q);\n      if (Math.abs(c.cur - c.drawn) < 0.0005) continue;\n      c.drawn = c.cur;\n      var e = backOut(c.cur);\n      c.el.style.transform = \"translate(0,\" + (c.y * (1 - e)).toFixed(2) + \"%) rotate(\" + (c.r * (1 - e)).toFixed(2) + \"deg)\";\n      c.el.style.opacity = String(Math.max(0, Math.min(1, e)));\n    }\n  }\n  // a new scroll position restarts each scrub tween from where it is now toward the new target\n  function onProgress(t) {\n    P = progress();\n    if (P === lastP) return;\n    lastP = P;\n    paintColours(P);\n    main.from = main.cur; main.to = P; main.t = t;\n    for (var i = 0; i < chars.length; i++) {\n      var c = chars[i], target = Math.min(1, Math.max(0, (P - c.ps) / (c.pe - c.ps)));\n      if (target !== c.to) { c.from = c.cur; c.to = target; c.t = t; }\n    }\n  }\n  function snapAll() {\n    P = progress(); lastP = P; lastColP = -1; paintColours(P);\n    main.from = main.to = main.cur = P; main.t = 0;\n    chars.forEach(function (c) { var v = Math.min(1, Math.max(0, (P - c.ps) / (c.pe - c.ps))); c.from = c.to = c.cur = v; c.t = 0; c.drawn = -1; });\n    paintLetters(now());\n  }\n\n  // autoplay: forward over the whole run, pause, back to the start, pause, again\n  function autoOn() { return !reduce && String(opts.auto) !== \"0\"; }\n  function autoStep(t) {\n    var max = Math.max(0, scroller.scrollHeight - scroller.clientHeight);\n    if (!auto) { var at = scroller.scrollTop; auto = { from: at, to: at < max * 0.5 ? max : 0, t: t + 1000 }; auto.d = auto.to > at ? 9000 : 2600; }\n    var p = (t - auto.t) / auto.d;\n    if (p < 0) return;\n    scroller.scrollTop = auto.from + (auto.to - auto.from) * sineInOut(Math.min(1, p));\n    if (p >= 1) { var back = auto.to > 0; auto = { from: auto.to, to: back ? 0 : max, t: t + (back ? 1500 : 1000), d: back ? 2600 : 9000 }; }\n  }\n  function pause(ms) { hold = Math.max(hold, now() + ms); auto = 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    if (autoOn() && t > hold) autoStep(t);\n    // render the scrub tweens first, then restart them toward the new scroll position (GSAP's ticker order), so a\n    // continuous scroll advances them by one frame of expo.out each frame instead of freezing them\n    paintLetters(t);\n    onProgress(t);\n    drawStars(dt);\n  }\n\n  function on(el, type, fn, opt) { el.addEventListener(type, fn, opt); offs.push(function () { el.removeEventListener(type, fn, opt); }); }\n  function onUser() { pause(4000); }\n\n  function update(next) {\n    opts = Object.assign({ theme: \"enrichr\", text: \"Design Bold. Ship Fast.\", length: 2.7, auto: \"1\", bgFrom: \"#fbf8f1\", bgTo: \"#e6ff55\", textFrom: \"#0c1e18\", textTo: \"#005236\", accent: \"#e6ff55\" }, opts, next || {});\n    opts.length = Math.max(0.5, num(opts.length, 2.7));\n    var th = THEMES[opts.theme] || [opts.bgFrom, opts.bgTo, opts.textFrom, opts.textTo];\n    cols = [hex(th[0], \"0c1e18\"), hex(th[1], \"005236\"), hex(th[2], \"fbf8f1\"), hex(th[3], \"e6ff55\")];\n    box.style.setProperty(\"--ef-hcm-acc\", opts.accent);\n    box.style.setProperty(\"--ef-hcm-bg\", th[0]);\n    if (reduce) stage.style.backgroundImage = \"linear-gradient(90deg,\" + th[0] + \",\" + th[1] + \")\";\n    if (destroyed) return;\n    split();\n    size();\n    if (reduce) { stage.style.backgroundColor = th[0]; textEl.style.color = th[2]; chars.forEach(function (c) { c.el.style.transform = \"\"; c.el.style.opacity = \"\"; }); }\n    else snapAll();\n  }\n\n  box.classList.toggle(\"ef-hcm--calm\", reduce);\n  update(o);\n  if (document.fonts && document.fonts.ready) document.fonts.ready.then(function () { if (!destroyed) { measure(); if (!reduce) snapAll(); } });\n  if (\"ResizeObserver\" in window) { ro = new ResizeObserver(function () { if (destroyed) return; var w = scroller.clientWidth, h = box.clientHeight; if (w !== W || h !== H) { size(); if (!reduce) snapAll(); } }); ro.observe(box); }\n  if (!reduce) {\n    if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(box); }\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() + 2000; });\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 (ro) ro.disconnect();\n    }\n  };\n}"
  }
}