Skip to content

Scrollbar Component ​

Scrollbar Component

Scrollbar component provides a custom-styled scrollbar container to replace the browser's native scrollbar, supporting both vertical and horizontal scrolling with customizable styles and behavior.

Basic Usage ​

The most basic usage is to create a scrollable container with a fixed height. When content exceeds the container height, a scrollbar will automatically appear.

Show CodeArrow
CopyGitHub

Permanent Scrollbar ​

By default, the scrollbar only appears on hover. Setting the permanent attribute to true makes the scrollbar always visible.

Show CodeArrow
CopyGitHub

Horizontal Scrolling ​

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

Show CodeArrow
CopyGitHub

Scroll Events ​

The scrollbar component provides vertical and horizontal scroll events to get real-time scroll position.

Vertical Scroll Event

Vertical scroll position: 0px

Horizontal Scroll Event

Horizontal scroll position: 0px
Show CodeArrow
CopyGitHub

Custom Height ​

You can specify the height of the scroll container through the height attribute.

Height: 200px

Height: 400px

Show CodeArrow
CopyGitHub

Scrollbar Component API ​

Attributes ​

AttributeDescriptionTypeAccepted ValuesDefault
heightContainer heightnumber—300
permanentWhether scrollbar is always visibleboolean—false

Events ​

Event NameDescriptionCallback Parameters
scroll-yVertical scroll event(element: HTMLElement)
scroll-xHorizontal scroll event(element: HTMLElement)
click-trackScrollbar track click event(element: HTMLElement)

Slots ​

Slot NameDescriptionScope Parameters
defaultContent of the scroll container—

Methods ​

The component exposes the following methods, which can be called through ref:

Method NameDescriptionParameters
scrollToScroll to specified position(options: ScrollToOptions)
updateScrollbarUpdate scrollbar state—
setScrollbarSet scrollbar position(mobile: number, direction: 'top' | 'left' | 'none')

Style Variables ​

Scrollbar component uses the following style variables, which can be customized through SCSS variables:

Variable NameDescription
$scrollbar-sizeScrollbar size
$scrollbar-bgScrollbar background color
$scrollbar-thumb-colorScrollbar thumb color
$bg-color-defaultDefault background color

Released under the MIT License