Skip to content

Scrollbar

Used to replace the browser's native scrollbar, providing a more consistent visual experience and powerful interaction control.

Basic Usage

Set the scrollbar height via the height attribute.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Basic Usage

Horizontal Scroll

When the content width exceeds the container width, a horizontal scrollbar will automatically appear.

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
Horizontal Scroll

Max Height

Use max-height attribute to limit the maximum height.

1
2
3
Max Height

Use in Nuxt

The Scrollbar component fully supports Nuxt 3/4 SSR rendering. When used in a Nuxt project, the component is automatically imported and no manual registration is required.

Nuxt SSR Item 1
Nuxt SSR Item 2
Nuxt SSR Item 3
Nuxt SSR Item 4
Nuxt SSR Item 5
Nuxt SSR Item 6
Nuxt SSR Item 7
Nuxt SSR Item 8
Nuxt SSR Item 9
Nuxt SSR Item 10
Nuxt Usage

SSR Notes:

  • ✅ Supports dynamic display of height and max-height
  • ✅ The custom scrollbar is activated on the client side without affecting the server-side first-screen rendering
  • ✅ Native scrollbar fallback mode (native) perfectly supports SSR

API

Props

AttributeDescriptionTypeAccepted ValuesDefault
heightScrollbar heightstring / number
max-heightScrollbar max heightstring / number
nativeWhether to use native scrollbarbooleanfalse
alwaysScrollbar is always displayedbooleanfalse
min-sizeMinimum scrollbar sizenumber20
view-classCustom class for viewstring
view-styleCustom style for viewstring / object / array
noresizeDo not respond to container size changesbooleanfalse
tagElement tag for viewstringdiv
theme-overridesTheme overridesComponentThemeVars

Events

Event NameDescriptionParameters
scrollScroll event{ scrollLeft, scrollTop }

Slots

SlotDescriptionSlot Props
defaultScrollable content.None

Methods

Method NameDescriptionParameters
scrollToScroll to specified position(options: ScrollToOptions | number, y?: number)
setScrollTopSet vertical scroll distance(value: number)
setScrollLeftSet horizontal scroll distance(value: number)
updateManually update scrollbar state

Expose

NameDescriptionType
wrapReference to the actual scroll container element.HTMLDivElement | undefined
updateManually refresh scrollbar state.() => void
scrollToScroll to a specific position.(arg1: ScrollbarScrollToArg, arg2?: number) => void
setScrollTopSet the vertical scroll offset.(value: number) => void
setScrollLeftSet the horizontal scroll offset.(value: number) => void

Theme Variables

Scrollbar component supports customizing local styles by overriding the following CSS variables:

VariableDescriptionDefault
--yh-scrollbar-widthScrollbar width6px
--yh-scrollbar-thumb-colorThumb color#c0c4cc
--yh-scrollbar-thumb-hover-colorThumb hover color#909399
--yh-scrollbar-track-colorTrack colortransparent
--yh-scrollbar-thumb-radiusThumb radius3px

Type Exports

NameDescription
YhScrollbarPropsComponent props type
YhScrollbarEmitsComponent emits type
YhScrollbarSlotsComponent slots type
YhScrollbarExposeComponent expose type
YhScrollbarScrollPayloadScroll event payload type
YhScrollbarScrollToArgscrollTo argument type
YhScrollbarInstanceComponent instance type

Released under the MIT License.