Skip to content
Latestv1.0.63

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.

Basic Usage

Horizontal Scroll ​

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

Horizontal Scroll

Max Height ​

Use max-height attribute to limit the maximum height. The example starts with more items so the scrolling and appended-content behavior is immediately visible.

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 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 scrollbarboolean—false
alwaysScrollbar is always displayedboolean—false
min-sizeMinimum scrollbar sizenumber—20
view-classCustom class for viewstring——
view-styleCustom style for viewstring / object / array——
noresizeDo not respond to container size changesboolean—false
tagElement tag for viewstring—div
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.