R

ReflexKR

Reflex 官方文档

组件工坊:Reflex 组件库 100 例

·

课程概览

布局

·

Box

·

Flex

·

Stack

·

Grid

·

Container

·

Section

·

Center

·

Spacer

·

Separator

·

Card

·

Inset

·

Aspect Ratio

·

Fragment

排版

·

Text

·

Heading

·

Link

·

Code

·

Markdown

·

Blockquote

·

Quote

·

Strong

·

Em

·

Kbd

表单

·

Button

·

Input

·

Text Area

·

Checkbox

·

Switch

·

Radio Group

·

Select

·

Slider

·

Form

·

Upload

数据展示

·

Badge

·

Avatar

·

Icon

·

Callout

·

List

·

Data List

·

Code Block

·

Progress

·

Spinner

·

Scroll Area

·

Moment

展开与切换

·

Tabs

·

Accordion

·

Segmented Control

浮层

·

Tooltip

·

Popover

·

Hover Card

·

Dialog

·

Alert Dialog

·

Drawer

·

Dropdown Menu

·

Context Menu

·

Toast

动态渲染

·

Cond

·

Match

·

Foreach

·

Auto Scroll

媒体

·

Image

·

Audio

·

Video

表格与数据网格

·

Table

·

Data Table

·

Data Editor

图表

·

Area Chart

·

Bar Chart

·

Line Chart

·

Composed Chart

·

Pie Chart

·

Radar Chart

·

Radial Bar Chart

·

Scatter Chart

·

Funnel Chart

·

Treemap

·

Sankey Chart

·

Error Bar

图表部件

·

Axis

·

Cartesian Grid

·

Chart Tooltip

·

Legend

·

Label

·

Reference

·

Brush

其他图表库

·

Plotly

·

Pyplot

HTML 元素

·

HTML

·

HTML Text

·

HTML Layout

·

HTML Forms

·

HTML Media

·

HTML Tables

·

SVG

其他工具

·

Theme

·

Skeleton

·

Clipboard

·

Html Embed

·

Script

·

Memo

组件工坊:Reflex 组件库 100 例
数据展示

Scroll Area

rx.scroll_area

官方文档

工坊订单

请把通知框的高度固定住,通知变多时只在框内滚动。

rx.scroll_area 是在固定尺寸内滚动内容的区域。它沿用浏览器自带的滚动功能,只是让滚动条在所有浏览器里画成同样的样子。必须给定高度(或宽度),里面才会出现滚动。

Three fundamental aspects of typography are legibility, readability, and aesthetics. Although in a non-technical sense legible and readable are often used synonymously, typographically they are separate but related concepts.

Legibility describes how easily individual characters can be distinguished from one another. For instance, if a b and an h, or a 3 and an 8, are difficult to distinguish at small sizes, this is a problem of legibility.

Typographers are concerned with legibility insofar as it is their job to select the correct font to use. Using only uppercase letters reduces legibility.

rx.scroll_area(
    rx.flex(
        rx.text(
            "Three fundamental aspects of typography are legibility, readability, and aesthetics. "
            "Although in a non-technical sense legible and readable are often used synonymously, "
            "typographically they are separate but related concepts."
        ),
        rx.text(
            "Legibility describes how easily individual characters can be distinguished from one another. "
            "For instance, if a b and an h, or a 3 and an 8, are difficult to distinguish at small sizes, "
            "this is a problem of legibility."
        ),
        rx.text(
            "Typographers are concerned with legibility insofar as it is their job to select the correct font to use. "
            "Using only uppercase letters reduces legibility."
        ),
        direction="column",
        spacing="4",
        padding_right="16px",
    ),
    type="always",
    scrollbars="vertical",
    height="180px",
)

试着改属性

下面的区域横向、纵向都会溢出。用 scrollbars 决定往哪个方向滚动,用 type 决定滚动条何时显示。

试着改属性

Card 1

Card 2

Card 3

Card 4

Card 5

Card 6

Card 7

Card 8

Card 9

Card 10

Card 11

Card 12

Card 13

Card 14

Card 15

Card 16

Card 17

Card 18

Card 19

Card 20

Card 21

Card 22

Card 23

Card 24

Card 25

Card 26

Card 27

Card 28

Card 29

Card 30

Card 31

Card 32

Card 33

Card 34

Card 35

Card 36

Card 37

Card 38

Card 39

Card 40

type

scrollbars

rx.scroll_area(
    rx.grid(
        *[rx.card(rx.text("Card ", i)) for i in range(1, 41)],
        columns="8",
        spacing="2",
        width="900px",
        padding="8px",
    ),
    type="hover",
    scrollbars="both",
    height="180px",
)
scrollbars 设为 vertical 时,横向溢出的部分不能滚动,会被裁掉。type 为 hover 或 scroll 时,只在鼠标悬停或滚动时显示滚动条。
属性取值默认值用途
scrollbars"vertical" "horizontal" "both""both"滚动方向
type"auto" "always" "scroll" "hover""hover"滚动条何时显示
scroll_hide_delay整数(毫秒)600scroll、hover 时停止操作后滚动条消失前的时间
height / widthCSS 长度无区域的尺寸。超出这个尺寸的内容可以滚动

决定滚动方向

scrollbars 决定沿哪条轴滚动。从左到右依次是只能纵向、只能横向、两个方向都可以。要横向滚动,里面的内容必须比区域更宽。

Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical. Vertical.

Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal. Horizontal.

Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways. Both ways.

rx.grid(
    rx.scroll_area(
        rx.text("Vertical. " * 40, size="2", padding="8px", padding_right="24px"),
        type="always",
        scrollbars="vertical",
        height="150px",
    ),
    rx.scroll_area(
        rx.text("Horizontal. " * 40, size="2", padding="8px", width="700px"),
        type="always",
        scrollbars="horizontal",
        height="150px",
    ),
    rx.scroll_area(
        rx.text("Both ways. " * 60, size="2", padding="8px", width="400px"),
        type="always",
        scrollbars="both",
        height="150px",
    ),
    columns="3",
    spacing="3",
)

滚动条何时显示

type 决定滚动条什么时候显示。

  • auto:只在内容溢出时显示。
  • always:不管溢出与否,一直显示。
  • scroll:沿该方向滚动期间显示。
  • hover:滚动期间以及鼠标悬停在区域上时显示。

type = 'auto'

Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished.

type = 'always'

Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished.

type = 'scroll'

Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished.

type = 'hover'

Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished. Legibility describes how easily individual characters can be distinguished.

rx.grid(
    *[
        rx.scroll_area(
            rx.flex(
                rx.text("type = '" + t + "'", weight="bold"),
                rx.text("Legibility describes how easily individual characters can be distinguished. " * 4, size="2"),
                direction="column",
                spacing="2",
                padding="8px",
                padding_right="20px",
            ),
            type=t,
            scrollbars="vertical",
            height="150px",
        )
        for t in ["auto", "always", "scroll", "hover"]
    ],
    columns="4",
    spacing="3",
)

消失的时间

type 为 "scroll" 或 "hover" 时,scroll_hide_delay 是停止操作后滚动条消失前的时间(毫秒)。分别滚动两个区域再停手,就能看出区别。

Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast. Hides fast.

Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds. Stays for 3 seconds.

rx.grid(
    rx.scroll_area(
        rx.text("Hides fast. " * 50, size="2", padding="8px", padding_right="20px"),
        type="scroll",
        scroll_hide_delay=200,
        height="120px",
    ),
    rx.scroll_area(
        rx.text("Stays for 3 seconds. " * 40, size="2", padding="8px", padding_right="20px"),
        type="scroll",
        scroll_hide_delay=3000,
        height="120px",
    ),
    columns="2",
    spacing="3",
)

完成订单

卡片里的通知列表固定了高度。通知再多,卡片大小也不变;鼠标悬停时会出现滚动条。

Notifications

Order #1001 has shipped.

Order #1002 has shipped.

Order #1003 has shipped.

Order #1004 has shipped.

Order #1005 has shipped.

Order #1006 has shipped.

Order #1007 has shipped.

Order #1008 has shipped.

Order #1009 has shipped.

Order #1010 has shipped.

Order #1011 has shipped.

Order #1012 has shipped.

Order #1013 has shipped.

Order #1014 has shipped.

Order #1015 has shipped.

rx.card(
    rx.text("Notifications", weight="bold", margin_bottom="2"),
    rx.scroll_area(
        rx.vstack(
            *[
                rx.hstack(
                    rx.avatar(fallback=str(i), size="2", radius="full"),
                    rx.text("Order #" + str(1000 + i) + " has shipped.", size="2"),
                    align="center",
                    padding_right="16px",
                )
                for i in range(1, 16)
            ],
            spacing="3",
        ),
        type="hover",
        scrollbars="vertical",
        height="220px",
    ),
    max_width="340px",
)

工坊笔记

  • 用 rx.scroll_area(内容, height=…) 只在固定尺寸内滚动。

  • scrollbars:vertical · horizontal · both(默认)。

  • type:auto · always · scroll · hover(默认)。scroll_hide_delay 控制消失时间。

  • 给里面的内容加一点 padding_right,以免滚动条挡住文字。

← 上一课

数据展示 · Spinner

下一课 →

数据展示 · Moment

订阅新课时和新课程通知

本课程新增课时或推出后续课程时,我们会发邮件通知你。

收集项目:电子邮箱 · 用途:本课程的新课时和上线通知 · 保存期限:直到你要求删除。不会用于其他用途,也不会提供给他人。回复任意通知邮件,我们会立即删除。

问答

关于本课有任何疑问都可以在这里留言。所有语言版本页面的提问会汇集在一起。

以纯文本显示,不支持链接和格式。

R

ReflexKR

动手学 Python 和 Reflex。所有示例均已在 Reflex 0.10.0 上实际运行验证。

ReflexKR 免费,没有横幅广告。如果对你有帮助,欢迎请我们喝杯咖啡。 ☕ 请我们喝杯咖啡

联盟链接与赞助说明
한국어English日本語简体中文EspañolDeutsch

© 2026 ReflexKR · Since 2026 · CC BY-NC 4.0

Built with Reflex