Scroll Area .mv-scroll-area

带细滚动条的滚动区域,自动隐藏,滚动驱动的边缘渐隐和吸附。

分类布局
类型纯 CSS(.mv-scroll-area)
状态稳定版
Keywordsscroll, scrollbar, fade, snap, overflow

When to use

  • A fixed-height region like a chat log, list or code block must scroll with a thin, styled scrollbar
  • Edge fades should hint that more content exists above, below or to the side
  • A horizontal row of chips or cards should scroll and snap each item into place

Avoid when

  • Items should be browsed with arrows, dots or autoplay rather than free scrolling → use Carousel instead
  • The whole page scrolls normally; nesting scroll regions for main content hurts usability

安装

node scripts/add.mjs scroll-area --out ./src/marvelous

使用 Marvelous UI MCP 服务器的 AI 智能体:install_components({ slugs: ["scroll-area"], target_dir: "<absolute path>/src/marvelous", framework: "react" })。

复制的文件(含依赖):tokens/tokens.css、core/base.css、components/scroll-area/scroll-area.css。

用法

标准标记,可在此基础上通过属性、data-* 和 CSS 变量进行定制:

<div style="display:flex;flex-wrap:wrap;gap:1.25rem;width:100%;min-width:0;max-width:44rem;align-items:start">
  <div style="flex:0 1 14rem;min-width:0;border:1px solid var(--mv-border);border-radius:var(--mv-radius-lg);background:var(--mv-surface);overflow:hidden">
  <div class="mv-scroll-area" data-fade data-autohide role="region" tabindex="0" aria-label="Versions" style="height:14rem">
    <ul style="list-style:none;margin:0;padding:.5rem 1rem;font-size:.875rem">
      <li style="padding:.4rem 0;font-weight:600">Versions</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.4.0: Tokens motion</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.3.2: Focus fix</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.3.1: Dialog swipe</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.3.0: Command palette</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.2.4: Stacked toasts</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.2.0: Calendar</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.1.0: Animated tabs</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v3.0.0: Web Components</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v2.9.1: Dark theme</li>
      <li style="padding:.4rem 0;border-top:1px solid var(--mv-border)">v2.9.0: CSS layers</li>
    </ul>
  </div>
  </div>
  <div class="mv-scroll-area" data-orientation="horizontal" data-fade data-snap="x" role="region" tabindex="0" aria-label="Gallery" style="flex:1 1 16rem;min-width:0;display:flex;gap:.75rem;padding-bottom:.5rem">
    <div role="img" aria-label="Coral gradient" style="flex:0 0 9rem;height:12rem;box-sizing:border-box;border:1px solid transparent;border-radius:var(--mv-radius-lg);background:linear-gradient(135deg,oklch(.8 .12 30),oklch(.6 .18 10))"></div>
    <div role="img" aria-label="Amber gradient" style="flex:0 0 9rem;height:12rem;box-sizing:border-box;border:1px solid transparent;border-radius:var(--mv-radius-lg);background:linear-gradient(135deg,oklch(.8 .12 90),oklch(.62 .16 60))"></div>
    <div role="img" aria-label="Lagoon gradient" style="flex:0 0 9rem;height:12rem;box-sizing:border-box;border:1px solid transparent;border-radius:var(--mv-radius-lg);background:linear-gradient(135deg,oklch(.8 .12 160),oklch(.55 .14 180))"></div>
    <div role="img" aria-label="Ocean gradient" style="flex:0 0 9rem;height:12rem;box-sizing:border-box;border:1px solid transparent;border-radius:var(--mv-radius-lg);background:linear-gradient(135deg,oklch(.8 .12 230),oklch(.55 .18 260))"></div>
    <div role="img" aria-label="Orchid gradient" style="flex:0 0 9rem;height:12rem;box-sizing:border-box;border:1px solid transparent;border-radius:var(--mv-radius-lg);background:linear-gradient(135deg,oklch(.8 .12 300),oklch(.55 .2 320))"></div>
    <div role="img" aria-label="Slate gradient" style="flex:0 0 9rem;height:12rem;box-sizing:border-box;border:1px solid transparent;border-radius:var(--mv-radius-lg);background:linear-gradient(135deg,oklch(.75 .08 270),oklch(.4 .1 270))"></div>
  </div>
</div>

API

Attributes

Name类型Description
data-orientationvertical | horizontalRestricts the scroll axis.
data-fadebooleanEdge fades that disappear at the start/end of the scroll.
data-autohidebooleanScrollbar only visible on hover/focus.
data-snapx | ySnaps the children.

CSS classes

NameDescription
mv-scroll-areaOn the scrolling container.

CSS variables

NameDefaultDescription
--mv-scroll-area-fade2.5remFade size.

Accessibility

Pure CSS, so the host adds the semantics: give the container role="region", tabindex="0" and an aria-label so it can be reached and scrolled with the keyboard (arrows, Page Up/Down, Home/End) and is announced as a named region; an aria-label on a plain div without a role is ignored by screen readers. The scrollbar stays native, so touch, wheel and assistive tech scrolling are untouched. Known limits: the edge fades need scroll-driven animations (animation-timeline) and are simply absent elsewhere; data-autohide hides the bar only on hover-capable devices and shows it again on hover or keyboard focus.

本页面由 AI 翻译。报告翻译问题