Ueage
Basic usage
Just wrap the components around the content you need to scroll through, set the container size, and the content will automatically allow scrolling and set a scrollbar (default vertical scrolling).
TIP
Because the container defaults to fill in the parent, components may not be able to stretch the parent size in containers without a height set.
Long content that can scroll
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
Long content that can scroll
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
Scrolling direction
Can use scroll
attribute to scroll only vertically or horizontally, or both.
both
: Vertically and horizontallyvertical
: Vertically.horizontal
: Horizontallynone
: No scroll.
scroll: both
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
Long content that can scroll
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
scroll: vertical
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
Long content that can scroll
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
scroll: horizontal
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
Long content that can scroll
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
scroll: none
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
Long content that can scroll
Hello. This is a simple scroll rect component for Vue3. You can wrap your long content with this component. So it can scroll.
It is easy to use!
It provides a simple scrollbar that can fade out and help you unify the display style of each browser.
It is easy to use!
Scroll bar style
You can modify scrollbar styles, colors, and more through CSS, and there are some CSS variables that can be used to modify scrollbar styles.
Name | Desc |
---|---|
--vue-scroll-rect-scrollbar-thumb-color | Color of scrollbar thumb |
--vue-scroll-rect-scrollbar-thumb-color-light | Color of scrollbar thumb when hover |
--vue-scroll-rect-scrollbar-thumb-color-pressed | Color of scrollbar thumb when pressed |
--vue-scroll-rect-scrollbar-thumb-radius | Border radius of scrollbar thumb |
--vue-scroll-rect-scrollbar-thumb-margin | Margin of scrollbar thumb |
--vue-scroll-rect-scrollbar-size | Width of scrollbar thumb |
Always show scroll bar
The scrollbar defaults will fade show when the mouse is moved in. You can set the scrollBarAlwaysShow
property to true
, and the scrollbar will keep visible state.
Set the scrollBarBackgroundClickable
property to true
and the scrollbar background clicking area can also trigger scrolling.
Custom scrollbar
If you want to replace the built-in scrollbar and use your own scrollbar component, you can achieve it through the slots scrollBarX
and scrollBarY
.
The slot will transmit the current scrollbar scrolling position and calculated length data (scrollBarValue
), and you can calculate the display position of the scrollbar based on this percentage; The onScroll
callback is used to control scrolling..
scrollBarValue struct:
Name | Type | Desc |
---|---|---|
show | boolean | Is scrollbar visible? |
size | number | Scroll bar calculation length (percentage, 0-100) |
sizeRaw | number | Scroll bar calculation length (pixel) |
pos | number | Scroll bar scrolling position (percentage, 0-100) |
Function onScroll:
Param | Name | Type |
---|---|---|
pos | number | Scroll bar scrolling position callback (percentage, 0-100) |
<template>
<ScrollRect class="long-content" scroll="both">
<ScrollContent />
<template #scrollBarY="{ scrollBarValue, onScroll }">
<MyScrollBar :value="scrollBarValue.pos" :size="scrollBarValue.size" @update:value="onScroll" />
</template>
</ScrollRect>
</template>