Back to Element Plus

Scrollbar

docs/en-US/component/scrollbar.md

2.13.77.3 KB
Original Source

Scrollbar

Used to replace the browser's native scrollbar.

Basic usage

:::demo Use height property to set the height of the scrollbar, or if not set, it adapts according to the parent container height.

scrollbar/basic-usage

:::

Horizontal scroll

:::demo When the element width is greater than the scrollbar width, the horizontal scrollbar is displayed.

scrollbar/horizontal-scroll

:::

Max height

:::demo The scrollbar is displayed only when the element height exceeds the max height.

scrollbar/max-height

:::

Manual scroll

:::demo Use setScrollTop and setScrollLeft methods can control scrollbar manually.

scrollbar/manual-scroll

:::

Infinite scroll ^(2.10.0)

:::demo end-reached is triggered when the scrollbar reaches the end. It can be used as an infinite scroll.

scrollbar/infinite-scroll

:::

API

Attributes

NameDescriptionTypeDefault
heightheight of scrollbar^[string] / ^[number]
max-heightmax height of scrollbar^[string] / ^[number]
nativewhether to use the native scrollbar style^[boolean]false
wrap-stylestyle of wrap container^[string] / ^[object]CSSProperties | CSSProperties[] | string[]
wrap-classclass of wrap container^[string]
view-stylestyle of view^[string] / ^[object]CSSProperties | CSSProperties[] | string[]
view-classclass of view^[string]
noresizedo not respond to container size changes, if the container size does not change, it is better to set it to optimize performance^[boolean]false
tagelement tag of the view^[string]div
alwaysalways show scrollbar^[boolean]false
min-sizeminimum size of scrollbar^[number]20
id ^(2.4.0)id of view^[string]
role ^(2.4.0) ^(a11y)role of view^[string]
aria-label ^(2.4.0) ^(a11y)aria-label of view^[string]
aria-orientation ^(2.4.0) ^(a11y)aria-orientation of view^[enum]'horizontal' | 'vertical'
tabindex ^(2.8.3)tabindex of wrap container^[number] / ^[string]
distance ^(2.10.5)trigger end-reached event distance(px)^[number]0

Events

NameDescriptionType
scrolltriggers when scrolling, return distance of scrolling^[Function]({ scrollLeft: number, scrollTop: number }) => void
end-reached ^(2.10.0)triggers when the end of a scroll is triggered^[Function](direction: 'top' | 'bottom' | 'left' | 'right') => void

Slots

NameDescription
defaultcustomize default content

Exposes

NameDescriptionType
handleScrollhandle scroll event^[Function]() => void
scrollToscrolls to a particular set of coordinates^[Function](options: ScrollToOptions | number, yCoord?: number) => void
setScrollTopSet distance to scroll top^[Function](scrollTop: number) => void
setScrollLeftSet distance to scroll left^[Function](scrollLeft: number) => void
updateupdate scrollbar state manually^[Function]() => void
wrapRefscrollbar wrap ref^[object]Ref<HTMLDivElement>