Skip to content

Type to search the docs, API, and blog.

↑↓ navigate↵ openesc close
  • Zazz 0.14 alpha

    API

    Scroll fade

    Fades the edges of a scroll container to hint at more content.

    Installation

    Source
    pnpm dlx zazz-ui add scroll-fade
    npx zazz-ui add scroll-fade
    yarn dlx zazz-ui add scroll-fade
    bunx zazz-ui add scroll-fade

    Run zazz-ui init first if the project has no zazz/ folder yet.

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Paint the right theme (background, form controls, scrollbars) before CSS loads -->
    <meta name="color-scheme" content="light dark">
    <!-- Zazz styles: base layers, then scroll-fade in cascade order -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_layers.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_variables.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_shadows.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_breakpoints.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_reset.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_view-transitions.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/scroll-fade/scroll-fade.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-flow.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-grid.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-spacing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-margin.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sizing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-color.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-effects.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-box.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-pseudo.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_defaults.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sr.css">
    <!-- Import map: bare specifiers in Zazz scripts resolve to pinned, SRI-checked files -->
    <script type="importmap">
    {
      "imports": {
        "signal-polyfill": "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js"
      },
      "integrity": {
        "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js": "sha384-0OqM7OXGT6Oz1z98u/geiFn/FUyz4iWexkXHCvbIGXRRDXl6bp6IKc0j78AQ6DEK"
      }
    }
    </script>
    <!-- Polyfill: Interest Invokers (interestfor) — native in Chromium only -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/invokers@2.2.2/dist/esm/production/interest.js" integrity="sha384-hR2BVNtsS7fIIMwOm+f7MY0JZfuByGhQQfevCBB6evFATKzBsTw0JzH/RxD94z2T" crossorigin="anonymous"></script>
    <!-- Zazz behavior: side-effect modules by tag; the rest via module imports -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/dialog-lifecycle.js"></script>
    <!-- Theme: apply the persisted (or preferred) scheme before first paint -->
    <script>
      (() => {
        try {
          // A stored choice pins the scheme with data-theme; with no choice the
          // page follows the system scheme.
          const storedTheme = localStorage.getItem("theme");
          if (storedTheme === "dark" || storedTheme === "light") {
            document.documentElement.dataset.theme = storedTheme;
          }
        } catch {
          /* no storage access: follow the system scheme */
        }
      })();
    </script>

    A <head> that loads the base layers and scroll-fade from jsDelivr, pinned to 0.14.2. To load the whole kit in two requests, see the CDN install.

    Examples

    The masks on this scroller fade its top and bottom edges as you scroll.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.

    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.

    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore.

    Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia.

    Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.

    one two three four
    <div
      style="
        --display: grid;
        --gap: 6;
      "
    >
      <div
        data-ui="scroll-fade"
        style="
          --p: 4;
          --h: 40;
          --overflow-y: auto;
        "
      >
        <p>The masks on this scroller fade its top and bottom edges as you scroll.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.</p>
        <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p>
        <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore.</p>
        <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia.</p>
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.</p>
      </div>
      <div
        data-ui="scroll-fade"
        data-scroll-fade-axis="x"
        style="
          --display: flex;
          --p: 4;
          --gap: 4;
          --overflow-x: auto;
        "
      >
        <ui-card
          style="
            --p: 4;
            --min-w: 60;
          "
        >
          one
        </ui-card>
        <ui-card
          style="
            --p: 4;
            --min-w: 60;
          "
        >
          two
        </ui-card>
        <ui-card
          style="
            --p: 4;
            --min-w: 60;
          "
        >
          three
        </ui-card>
        <ui-card
          style="
            --p: 4;
            --min-w: 60;
          "
        >
          four
        </ui-card>
      </div>
    </div>
    /**
     * scroll-fade.css — Scroll fade ([data-ui~="scroll-fade"]): edge masks on a scroller
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css
     * @uses       mask-image + scroll-driven animation (animation-timeline: scroll(self));
     *             where scroll timelines are unsupported the fades are static
     * @tokens     --ui-scroll-fade-* (@layer variables)
     * @presets    data-scroll-fade-axis="y | x" (y when absent)
     *
     * The mask fades the element's start and end edges along the scroll axis, and
     * the scroll timeline reveals each edge only while there is content beyond it.
     * Hooks: --ui-scroll-fade-size (depth of each fade), --ui-scroll-fade-reveal (the
     * scroll distance over which an edge fades in), --ui-scroll-fade-mask (replace the
     * whole mask). The animated per-edge depths are registered privates.
     */
    
    @layer variables {
      :root {
        --ui-scroll-fade-size: min(12%, calc(var(--spacing) * 10));
        --ui-scroll-fade-reveal: calc(var(--spacing) * 24);
      }
    }
    
    /* the composed mask (a private the axis preset rewrites) and the animated per-edge fade depths */
    @property --_scroll-fade-gradient {
      syntax: "*";
      inherits: false;
    }
    @property --_scroll-fade-start {
      syntax: "<length-percentage>";
      inherits: false;
      initial-value: 0px;
    }
    @property --_scroll-fade-end {
      syntax: "<length-percentage>";
      inherits: false;
      initial-value: 0px;
    }
    
    @keyframes ui-scroll-fade-reveal-start {
      from {
        --_scroll-fade-start: 0px;
      }
      to {
        --_scroll-fade-start: var(--ui-scroll-fade-size);
      }
    }
    
    @keyframes ui-scroll-fade-reveal-end {
      from {
        --_scroll-fade-end: var(--ui-scroll-fade-size);
      }
      to {
        --_scroll-fade-end: 0px;
      }
    }
    
    @layer ui.components {
      :where([data-ui~="scroll-fade"]) {
        --_scroll-fade-gradient: linear-gradient(
          to bottom,
          transparent 0,
          #000 var(--_scroll-fade-start),
          #000 calc(100% - var(--_scroll-fade-end)),
          transparent 100%
        );
        -webkit-mask-image: var(--ui-scroll-fade-mask, var(--_scroll-fade-gradient));
        mask-image: var(--ui-scroll-fade-mask, var(--_scroll-fade-gradient));
        -webkit-mask-composite: source-in;
        mask-composite: intersect;
        -webkit-mask-repeat: no-repeat;
        mask-repeat: no-repeat;
    
        @supports (animation-timeline: scroll()) {
          animation:
            ui-scroll-fade-reveal-start 1ms ease-in-out,
            ui-scroll-fade-reveal-end 1ms ease-in-out;
        }
    
        @supports not (animation-timeline: scroll()) {
          --_scroll-fade-start: var(--ui-scroll-fade-size);
          --_scroll-fade-end: var(--ui-scroll-fade-size);
        }
      }
    
      /* The timeline longhands sit in their own block, apart from the `animation`
         shorthand above. Lightning CSS, which minifies dist/zazz.css, folds the
         longhands of a block into the shorthand, timeline included
         (parcel-bundler/lightningcss#1369), and browsers drop an `animation` that
         names a `scroll()` timeline, so the bundle's fades never ran. Fill mode
         rides along so the shorthand stands alone and is not expanded either. */
      @supports (animation-timeline: scroll()) {
        :where([data-ui~="scroll-fade"]) {
          animation-timeline: scroll(self block), scroll(self block);
          animation-range:
            0 var(--ui-scroll-fade-reveal),
            calc(100% - var(--ui-scroll-fade-reveal)) 100%;
          animation-fill-mode: both;
        }
      }
    
      :where([data-ui~="scroll-fade"][data-scroll-fade-axis="x"]) {
        --_scroll-fade-gradient: linear-gradient(
          to right,
          transparent 0,
          #000 var(--_scroll-fade-start),
          #000 calc(100% - var(--_scroll-fade-end)),
          transparent 100%
        );
    
        &:where(:dir(rtl)) {
          --_scroll-fade-gradient: linear-gradient(
            to left,
            transparent 0,
            #000 var(--_scroll-fade-start),
            #000 calc(100% - var(--_scroll-fade-end)),
            transparent 100%
          );
        }
    
        @supports (animation-timeline: scroll()) {
          animation-timeline: scroll(self inline), scroll(self inline);
        }
      }
    }

    Attributes

    scroll-fade attributes
    AttributeKindValuesNotes
    data-ui="scroll-fade"Identityfree valueIdentity token in data-ui.
    data-scroll-fade-axisPresetxPreset: a named bundle of values.

    Hooks

    Set a hook on :root, on a subtree, or inline on one element. A state hook (--…--hover) themes that state only; the primitive keeps its other states.

    scroll-fade hooks
    HookDefaultState
    --ui-scroll-fade-revealcalc(var(--spacing) * 24)—
    --ui-scroll-fade-sizemin(12%, calc(var(--spacing) * 10))—

    API