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
|
2024-03-22 14:22:42 +08:00
|
|
|
|
description: A set of carousel areas.
|
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
|
|
|
|
---
|
|
|
|
|
|
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>
|
2024-04-19 17:17:56 +08:00
|
|
|
|
<code src="./demo/arrows.tsx" version="5.17.0">Arrows for switching</code>
|
2023-05-19 14:58:40 +08:00
|
|
|
|
<code src="./demo/component-token.tsx" debug>Component Token</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2016-06-19 11:19:36 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
Common props ref:[Common props](/docs/react/common-props)
|
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
2019-05-07 14:57:32 +08:00
|
|
|
|
| --- | --- | --- | --- | --- |
|
2024-04-19 17:17:56 +08:00
|
|
|
|
| arrows | Whether to show switch arrows | boolean | false | 5.17.0 |
|
2020-06-17 23:18:14 +08:00
|
|
|
|
| autoplay | Whether to scroll automatically | boolean | false | |
|
2023-11-11 12:03:39 +08:00
|
|
|
|
| autoplaySpeed | Delay between each auto scroll (in milliseconds) | number | 3000 | |
|
2024-06-11 12:35:14 +08:00
|
|
|
|
| adaptiveHeight | Adjust the slide's height 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` | |
|
2024-08-16 15:51:45 +08:00
|
|
|
|
| dots | Whether to show the dots at the bottom of the gallery, `object` for `dotsClass` | boolean \| { className?: string } | true | |
|
2024-06-11 12:35:14 +08:00
|
|
|
|
| draggable | Enable scrollable via dragging on desktop | boolean | false | |
|
2023-11-11 12:03:39 +08:00
|
|
|
|
| fade | Whether to use fade transition | boolean | false | |
|
|
|
|
|
| infinite | Infinitely wrap around contents | boolean | true | |
|
|
|
|
|
| speed | Animation speed in milliseconds | number | 500 | |
|
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 | - | |
|
2023-11-11 12:03:39 +08:00
|
|
|
|
| waitForAnimate | Whether to wait for the animation when switching | boolean | false | |
|
2016-06-19 11:19:36 +08:00
|
|
|
|
|
2024-06-11 12:35:14 +08:00
|
|
|
|
Find more APIs in react-slick [documentation](https://react-slick.neostack.com/docs/api).
|
|
|
|
|
|
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
|
|
|
|
|
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).
|