File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
components/virtual-scroller
docs/.vitepress/components/virtualScroller Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,14 @@ export const virtualScrollerProps = {
55
55
renderItemList : {
56
56
type : Function as PropType < ( itemVNodes : VNodeChild ) => VNodeChild > ,
57
57
} ,
58
+ topThreshold : {
59
+ type : Number ,
60
+ default : 0 ,
61
+ } ,
62
+ bottomThreshold : {
63
+ type : Number ,
64
+ default : 0 ,
65
+ } ,
58
66
} as const satisfies ComponentObjectPropsOptions ;
59
67
60
68
export type VirtualScrollerProps = ExtractPublicPropTypes < typeof virtualScrollerProps > ;
@@ -139,15 +147,20 @@ export default defineComponent({
139
147
getClientSize,
140
148
} ) ;
141
149
150
+ let lastScrollTop = 0 ;
142
151
const onScroll = ( e : Event ) => {
143
152
emit ( 'scroll' , e ) ;
153
+ const currentScrollTop = ( e . target as HTMLElement ) . scrollTop ;
154
+ const isScrollUp = currentScrollTop < lastScrollTop ;
155
+ lastScrollTop = currentScrollTop ;
156
+
144
157
const offset = getOffset ( ) ;
145
158
const scrollSize = getScrollSize ( ) ;
146
159
const clientSize = getClientSize ( ) ;
147
- if ( offset === 0 ) {
160
+ if ( isScrollUp && offset <= props . topThreshold ) {
148
161
emit ( 'toTop' ) ;
149
162
}
150
- if ( offset + clientSize >= scrollSize ) {
163
+ if ( ! isScrollUp && offset + clientSize >= scrollSize - props . bottomThreshold ) {
151
164
emit ( 'toBottom' ) ;
152
165
}
153
166
} ;
Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ scroll.vue
49
49
| wrapTag | 列表包裹元素名称 | string | ` div ` |
50
50
| wrapClass | 列表包裹元素类名 | string | - |
51
51
| wrapStyle | 列表包裹元素内联样式 | object | ` {} ` |
52
+ | topThreshold | 触发` toTop ` 事件的阈值 | number | 0 |
53
+ | bottomThreshold | 触发` toBottom ` 事件的阈值 | number | 0 |
52
54
| scrollbarProps | 滚动条样式,参考滚动条组件 | object | - |
53
55
54
56
## VirtualScroller Events
You can’t perform that action at this time.
0 commit comments