组件工坊: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
rx.scroll_area官方文档
工坊订单
请把通知框的高度固定住,通知变多时只在框内滚动。
rx.scroll_area 是在固定尺寸内滚动内容的区域。它沿用浏览器自带的滚动功能,只是让滚动条在所有浏览器里画成同样的样子。必须给定高度(或宽度),里面才会出现滚动。
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 决定滚动条何时显示。
试着改属性
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" "horizontal" "both" | "both" | 滚动方向 |
type | "auto" "always" "scroll" "hover" | "hover" | 滚动条何时显示 |
scroll_hide_delay | 整数(毫秒) | 600 | scroll、hover 时停止操作后滚动条消失前的时间 |
height / width | CSS 长度 | 无 | 区域的尺寸。超出这个尺寸的内容可以滚动 |
scrollbars 决定沿哪条轴滚动。从左到右依次是只能纵向、只能横向、两个方向都可以。要横向滚动,里面的内容必须比区域更宽。
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:滚动期间以及鼠标悬停在区域上时显示。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 是停止操作后滚动条消失前的时间(毫秒)。分别滚动两个区域再停手,就能看出区别。
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
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,以免滚动条挡住文字。
订阅新课时和新课程通知
本课程新增课时或推出后续课程时,我们会发邮件通知你。
问答
关于本课有任何疑问都可以在这里留言。所有语言版本页面的提问会汇集在一起。