File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -111,14 +111,26 @@ export const SideBar: FC<Partial<TaroSideBarProps>> & {
111
111
const titleRectRef = useRef < RectItem [ ] > ( [ ] )
112
112
const [ scrollTop , setScrollTop ] = useState ( 0 )
113
113
const scrollDirection = ( to : number ) => {
114
+ if ( sidebarDuration === 0 ) {
115
+ setScrollTop ( to )
116
+ return
117
+ }
118
+
119
+ const from = scrollTop
120
+ const frames = Math . round ( sidebarDuration / 16 )
114
121
let count = 0
115
- const frames = sidebarDuration === 0 ? 1 : Math . round ( sidebarDuration / 16 )
122
+
116
123
function animate ( ) {
117
- setScrollTop ( to )
118
- if ( ++ count < frames ) {
124
+ const progress = count / frames
125
+ const current = from + ( to - from ) * progress
126
+ setScrollTop ( current )
127
+
128
+ if ( count < frames ) {
129
+ count ++
119
130
raf ( animate )
120
131
}
121
132
}
133
+
122
134
animate ( )
123
135
}
124
136
const scrollIntoView = ( index : number ) => {
You can’t perform that action at this time.
0 commit comments