Scrollbar 滚动条 ​

用于替换浏览器原生滚动条。

基础用法 ​

通过 height 属性设置滚动条高度,若不设置则根据父容器高度自适应。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

横向滚动 ​

当元素宽度大于滚动条宽度时,会显示横向滚动条。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

Scroll masks 2.14.8 ​

Use mask to indicate that more content can be scrolled to above, below, to the left, or to the right of the viewport. Masks are disabled by default.

值Behavior
falseDisable all masks (default).
trueEnable all four masks, according to the available overflow.
'top'Enable only the top mask.
'bottom'Enable only the bottom mask.
'left'Enable only the left mask.
'right'Enable only the right mask.
vue
<template>
  <el-scrollbar height="240px" mask />
  <el-scrollbar height="240px" mask="top" />
  <el-scrollbar height="240px" mask="bottom" />
  <el-scrollbar mask="left" />
  <el-scrollbar mask="right" />
</template>

Scroll vertically or horizontally and change the mask mode. Each enabled mask appears only while there is more content in its direction. It disappears when that edge is reached. Masks stay hidden on axes without overflow; when both axes overflow, all four masks can appear together.

Vertical scrolling

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

Horizontal scrolling

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

Masks fade in and out over 200ms by default, using --el-transition-duration-fast. The animation is disabled when the user prefers reduced motion. Masks do not block pointer events or cover scrollbar controls, and also work with native.

left and right refer to the physical edges of the viewport, including when the scroll container uses direction: rtl.

The distance attribute only affects the end-reached event; it does not change when masks appear. When using noresize, call update() after changing the content or container size to refresh the masks.

Customize masks ​

Use the following CSS variables on the Scrollbar component to customize each mask:

CSS variable说明默认值
--el-scrollbar-top-mask-heightHeight of the top mask.40px
--el-scrollbar-bottom-mask-heightHeight of the bottom mask.40px
--el-scrollbar-left-mask-widthWidth of the left mask.40px
--el-scrollbar-right-mask-widthWidth of the right mask.40px
--el-scrollbar-top-mask-colorColor of the top mask.var(--el-bg-color)
--el-scrollbar-bottom-mask-colorColor of the bottom mask.var(--el-bg-color)
--el-scrollbar-left-mask-colorColor of the left mask.var(--el-bg-color)
--el-scrollbar-right-mask-colorColor of the right mask.var(--el-bg-color)

The default color follows the light or dark theme. Set the mask colors to match the container background when using a custom background. The example above sets the vertical mask heights and horizontal mask widths to 48px.

最大高度 ​

当元素高度超过最大高度,才会显示滚动条。

1

2

3

手动滚动 ​

通过使用 setScrollTop 与 setScrollLeft 方法,可以手动控制滚动条滚动。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

无限滚动2.10.0 ​

end-reached 是在滚动条到达底部时触发的。它可以用作无限滚动。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

API ​

Attributes ​

属性名说明类型Default
height滚动条高度string / number—
max-height滚动条最大高度string / number—
native是否使用原生滚动条样式booleanfalse
wrap-style包裹容器的自定义样式string / object—
wrap-class包裹容器的自定义类名string—
view-style视图的自定义样式string / object—
view-class视图的自定义类名string—
noresize不响应容器尺寸变化,如果容器尺寸不会发生变化,最好设置它可以优化性能booleanfalse
tag视图的元素标签stringdiv
always滚动条总是显示boolean你好
mask 2.14.8Gradient masks: true for all edges, a direction for one edge, and false to disableboolean / enum你好
min-size滚动条最小尺寸number20
id 2.4.0视图IDstring—
role 2.4.0 a11y视图的角色string—
aria-label 2.4.0 a11y视图的 aria-labelstring—
aria-orientation 2.4.0 a11y视图的 aria-orientationenum—
tabindex 2.8.3容器的tabindexnumber / string—
distance 2.10.5触发到达底部事件的距离(像素)number0

Events ​

事件名说明类型
scroll当触发滚动事件时,返回滚动的距离Function
end-reached 2.10.0触发滚动结束时的触发器Function

Slots ​

插槽名说明
default自定义默认内容

Exposes ​

名称Description类型
handleScroll触发滚动事件Function
scrollTo滚动到一组特定坐标Function
setScrollTop设置滚动条到顶部的距离Function
setScrollLeft设置滚动条到左边的距离Function
update手动更新滚动条状态Function
wrapRef滚动条包裹的 ref 对象object

源代码 ​

组件 • 样式 • 文档

贡献者 ​