Carousel 走马灯
走马灯,轮播图
代码演示
示例
import { Carousel } from 'antd-mobile';
const App = React.createClass({
render() {
return (<div>
<div style={{ color: '#888', margin: '0.2rem' }}>normal</div>
<Carousel
className="my-carousel" autoplay={false} infinite
beforeChange={(from, to) => console.log(`slide from ${from} to ${to}`)}
afterChange={(index) => console.log('slide to', index)}
>
{['AiyWuByWklrrUDlFignR', 'TekJlZRVCjLFexlOCuWn', 'AiyWuByWklrrUDlFignR'].map((ii) => (
<a href="#" key={ii}><img src={`https://zos.alipayobjects.com/rmsportal/${ii}.png`} /></a>
))}
</Carousel>
<div style={{ color: '#888', margin: '0.2rem' }}>vertical</div>
<Carousel className="my-carousel"
dots={false} dragging={false} swiping={false} autoplay infinite vertical
>
<div className="v-item">Carousel 1</div>
<div className="v-item">Carousel 2</div>
<div className="v-item">Carousel 3</div>
</Carousel>
</div>);
},
});
ReactDOM.render(<App />, mountNode);
.my-carousel {
background: #fff;
}
.my-carousel a {
display: inline-block;
width: 100%;
margin: 0; padding: 0;
}
.my-carousel a img {
width: 100%;
vertical-align: top;
}
.my-carousel .v-item {
height: 0.72rem;
line-height: 0.72rem;
padding-left: 0.2rem;
}
API ( 适用平台:WEB、React-Native )
参数 | 说明 | 类型 | 默认值 |
---|
selectedIndex | 手动设置当前显示的索引 | number | 0 |
dots | 是否显示面板指示点 | Boolean | true |
vertical | 垂直显示(web 为内容,rn 为 pagination) | Boolean | false |
autoplay | 是否自动切换 | Boolean | false |
infinite | 是否循环播放 | Boolean | false |
afterChange | 切换面板后的回调函数 | (current: number): void | 无 |
easing (web only ) | 动画效果 | String | linear |
beforeChange (web only ) | 切换面板前的回调函数 | (from: number, to: number): void | 无 |
onScrollBeginDrag (rn only ) | 见 react-native scrollView onScrollBeginDrag | (): void | 无 |
bounces (rn only ) | 见 react-native scrollView bounces | Boolean | true |
更多参数可参考:https://github.com/FormidableLabs/nuka-carousel