Skip to content

Commit 6266c01

Browse files
lqr131115qrliu97
andauthored
fix: Carousel scrollToStart not work in infinite(#1442)
Co-authored-by: qingruiliu <[email protected]>
1 parent f0defb5 commit 6266c01

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

components/carousel/index.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,26 @@ class Carousel extends React.PureComponent<CarouselProps, CarouselState> {
324324

325325
scrollToStart = () => {
326326
this.scrollview?.current?.scrollTo({
327-
x: this.props.vertical ? 0 : this.state.width,
328-
y: this.props.vertical ? this.state.height : 0,
327+
x: this.props.vertical ? 0 : this.props.infinite ? this.state.width : 0,
328+
y: this.props.vertical
329+
? this.props.infinite
330+
? this.state.height
331+
: 0
332+
: 0,
329333
animated: false,
330334
})
331335
}
332336

333337
scrollToEnd = () => {
334338
this.scrollview?.current?.scrollTo({
335-
x: this.props.vertical ? 0 : this.state.width * this.count,
336-
y: this.props.vertical ? this.state.height * this.count : 0,
339+
x: this.props.vertical
340+
? 0
341+
: this.state.width *
342+
(this.props.infinite ? this.count : this.count - 1),
343+
y: this.props.vertical
344+
? this.state.height *
345+
(this.props.infinite ? this.count : this.count - 1)
346+
: 0,
337347
animated: false,
338348
})
339349
}

0 commit comments

Comments
 (0)