2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: 数据展示
|
2016-06-19 11:19:36 +08:00
|
|
|
|
title: Carousel
|
|
|
|
|
subtitle: 走马灯
|
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-03-31 14:17:09 +08:00
|
|
|
|
---
|
2015-08-01 14:08:04 +08:00
|
|
|
|
|
2015-08-05 21:18:34 +08:00
|
|
|
|
旋转木马,一组轮播的区域。
|
2015-08-03 14:52:26 +08:00
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
2015-08-05 21:18:34 +08:00
|
|
|
|
- 当有一组平级的内容。
|
|
|
|
|
- 当内容空间不足时,可以用走马灯的形式进行收纳,进行轮播展现。
|
|
|
|
|
- 常用于一组图片或卡片轮播。
|
2015-08-03 14:52:26 +08:00
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/basic.tsx">基本</code>
|
|
|
|
|
<code src="./demo/position.tsx">位置</code>
|
|
|
|
|
<code src="./demo/autoplay.tsx">自动切换</code>
|
|
|
|
|
<code src="./demo/fade.tsx">渐显</code>
|
2023-05-19 14:58:40 +08:00
|
|
|
|
<code src="./demo/component-token.tsx" debug>组件 Token</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2015-08-03 14:52:26 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| autoplay | 是否自动切换 | boolean | false | |
|
2020-07-01 22:15:26 +08:00
|
|
|
|
| dotPosition | 面板指示点位置,可选 `top` `bottom` `left` `right` | string | `bottom` | |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| dots | 是否显示面板指示点,如果为 `object` 则同时可以指定 `dotsClass` 或者 | boolean \| { className?: string } | true | |
|
2023-04-25 10:08:35 +08:00
|
|
|
|
| waitForAnimate | 是否等待切换动画 | boolean | false | |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| easing | 动画效果 | string | `linear` | |
|
|
|
|
|
| effect | 动画效果函数 | `scrollx` \| `fade` | `scrollx` | |
|
2023-03-28 18:14:53 +08:00
|
|
|
|
| afterChange | 切换面板的回调 | (current: number) => void | - | |
|
|
|
|
|
| beforeChange | 切换面板的回调 | (current: number, next: number) => void | - | |
|
2015-11-05 18:29:30 +08:00
|
|
|
|
|
2017-10-10 13:41:04 +08:00
|
|
|
|
## 方法
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| 名称 | 描述 |
|
|
|
|
|
| ------------------------------ | ------------------------------------------------- |
|
2019-11-20 20:31:43 +08:00
|
|
|
|
| goTo(slideNumber, dontAnimate) | 切换到指定面板, dontAnimate = true 时,不使用动画 |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| next() | 切换到下一面板 |
|
|
|
|
|
| prev() | 切换到上一面板 |
|
2017-10-10 13:41:04 +08:00
|
|
|
|
|
2020-04-19 00:51:56 +08:00
|
|
|
|
更多 API 可参考:<https://react-slick.neostack.com/docs/api>
|
2021-05-06 14:37:39 +08:00
|
|
|
|
|
2023-08-30 23:02:35 +08:00
|
|
|
|
## 主题变量(Design Token)
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Carousel"></ComponentTokenTable>
|
|
|
|
|
|
2021-05-06 14:37:39 +08:00
|
|
|
|
## FAQ
|
|
|
|
|
|
|
|
|
|
### 如何自定义箭头?
|
|
|
|
|
|
|
|
|
|
可参考 [#12479](https://github.com/ant-design/ant-design/issues/12479)。
|