2016-06-19 11:19:36 +08:00
|
|
|
---
|
|
|
|
category: Components
|
2022-11-09 12:28:04 +08:00
|
|
|
group: Data Display
|
2016-06-19 11:19:36 +08:00
|
|
|
title: Carousel
|
2022-11-30 20:14:41 +08:00
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*bPMSSqbaTMkAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*a-58QpYnqOsAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
demo:
|
|
|
|
cols: 2
|
2016-06-19 11:19:36 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
A carousel component. Scales with its container.
|
|
|
|
|
2016-09-10 13:43:30 +08:00
|
|
|
## When To Use
|
2016-06-19 11:19:36 +08:00
|
|
|
|
|
|
|
- When there is a group of content on the same level.
|
2017-09-16 11:27:46 +08:00
|
|
|
- When there is insufficient content space, it can be used to save space in the form of a revolving door.
|
2016-11-29 17:13:24 +08:00
|
|
|
- Commonly used for a group of pictures/cards.
|
2016-06-19 11:19:36 +08:00
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
## Examples
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
<code src="./demo/basic.tsx">Basic</code>
|
|
|
|
<code src="./demo/position.tsx">Position</code>
|
|
|
|
<code src="./demo/autoplay.tsx">Scroll automatically</code>
|
|
|
|
<code src="./demo/fade.tsx">Fade in</code>
|
|
|
|
|
2016-06-19 11:19:36 +08:00
|
|
|
## API
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
| Property | Description | Type | Default | Version |
|
2019-05-07 14:57:32 +08:00
|
|
|
| --- | --- | --- | --- | --- |
|
2020-06-17 23:18:14 +08:00
|
|
|
| autoplay | Whether to scroll automatically | boolean | false | |
|
2020-07-01 22:15:26 +08:00
|
|
|
| dotPosition | The position of the dots, which can be one of `top` `bottom` `left` `right` | string | `bottom` | |
|
|
|
|
| dots | Whether to show the dots at the bottom of the gallery, `object` for `dotsClass` and any others | boolean \| { className?: string } | true | |
|
2023-04-25 10:08:35 +08:00
|
|
|
| waitForAnimate | Whether to wait for the animation when switching | boolean | false | |
|
2019-05-07 14:57:32 +08:00
|
|
|
| easing | Transition interpolation function name | string | `linear` | |
|
|
|
|
| effect | Transition effect | `scrollx` \| `fade` | `scrollx` | |
|
2023-03-28 18:14:53 +08:00
|
|
|
| afterChange | Callback function called after the current index changes | (current: number) => void | - | |
|
|
|
|
| beforeChange | Callback function called before the current index changes | (current: number, next: number) => void | - | |
|
2016-06-19 11:19:36 +08:00
|
|
|
|
2017-10-10 13:41:04 +08:00
|
|
|
## Methods
|
|
|
|
|
2019-11-20 20:31:43 +08:00
|
|
|
| Name | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| goTo(slideNumber, dontAnimate) | Go to slide index, if dontAnimate=true, it happens without animation |
|
|
|
|
| next() | Change current slide to next slide |
|
|
|
|
| prev() | Change current slide to previous slide |
|
2017-10-10 13:41:04 +08:00
|
|
|
|
2020-04-19 00:51:56 +08:00
|
|
|
Find more APIs in react-slick [documentation](https://react-slick.neostack.com/docs/api).
|
2021-05-06 14:37:39 +08:00
|
|
|
|
2023-04-11 10:25:24 +08:00
|
|
|
## Design Token
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Carousel"></ComponentTokenTable>
|
|
|
|
|
2021-05-06 14:37:39 +08:00
|
|
|
## FAQ
|
|
|
|
|
|
|
|
### How to add custom arrows?
|
|
|
|
|
|
|
|
See [#12479](https://github.com/ant-design/ant-design/issues/12479).
|