File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -65,30 +65,31 @@ export const useScrollWatch = (props: useScrollWathType) => {
65
65
66
66
return - 1 ;
67
67
} ;
68
- const refreshScrollTop = debounce ( ( ) => {
68
+ const refresh = debounce ( ( ) => {
69
69
setScrollTop ( getScrollTop ( ) ) ;
70
+ setPosList ( getPosList ( ) ) ;
70
71
} , 100 ) ;
71
72
72
73
const [ posList , setPosList ] = useState < number [ ] > ( [ ] ) ;
73
74
74
75
useEffect ( ( ) => {
75
- setPosList ( getPosList ( ) ) ;
76
+ refresh ( ) ;
76
77
} , [ ref ] ) ;
77
78
78
79
const curIndex = getCurIndex ( scrollTop , posList ) ;
79
80
80
81
useEffect ( ( ) => {
81
82
if ( ! ref . current ) return ;
82
83
const elm = isWindowScrollParent ( ref . current ) ? window : ref . current ;
83
- const observer = new window . MutationObserver ( debounce ( getPosList , 1000 ) ) ;
84
+ const observer = new window . MutationObserver ( refresh ) ;
84
85
observer . observe ( ref . current , {
85
86
childList : true ,
86
87
subtree : true ,
87
88
} ) ;
88
- elm . addEventListener ( 'scroll' , refreshScrollTop ) ;
89
+ elm . addEventListener ( 'scroll' , refresh ) ;
89
90
return ( ) => {
90
91
observer . disconnect ( ) ;
91
- elm && elm . removeEventListener ( 'scroll' , refreshScrollTop ) ;
92
+ elm && elm . removeEventListener ( 'scroll' , refresh ) ;
92
93
} ;
93
94
} , [ ref ] ) ;
94
95
You can’t perform that action at this time.
0 commit comments