Carousel 走马灯

走马灯,轮播图

代码演示

示例

  1. import { Carousel } from 'antd-mobile';
  2. const App = React.createClass({
  3. render() {
  4. return (<div>
  5. <div style={{ color: '#888', margin: '0.2rem' }}>normal</div>
  6. <Carousel
  7. className="my-carousel" autoplay={false} infinite
  8. beforeChange={(from, to) => console.log(`slide from ${from} to ${to}`)}
  9. afterChange={(index) => console.log('slide to', index)}
  10. >
  11. {['AiyWuByWklrrUDlFignR', 'TekJlZRVCjLFexlOCuWn', 'AiyWuByWklrrUDlFignR'].map((ii) => (
  12. <a href="#" key={ii}><img src={`https://zos.alipayobjects.com/rmsportal/${ii}.png`} /></a>
  13. ))}
  14. </Carousel>
  15. <div style={{ color: '#888', margin: '0.2rem' }}>vertical</div>
  16. <Carousel className="my-carousel"
  17. dots={false} dragging={false} swiping={false} autoplay infinite vertical
  18. >
  19. <div className="v-item">Carousel 1</div>
  20. <div className="v-item">Carousel 2</div>
  21. <div className="v-item">Carousel 3</div>
  22. </Carousel>
  23. </div>);
  24. },
  25. });
  26. ReactDOM.render(<App />, mountNode);
  1. .my-carousel {
  2. background: #fff;
  3. }
  4. .my-carousel a {
  5. display: inline-block;
  6. width: 100%;
  7. margin: 0; padding: 0;
  8. }
  9. .my-carousel a img {
  10. width: 100%;
  11. vertical-align: top;
  12. }
  13. .my-carousel .v-item {
  14. height: 0.72rem;
  15. line-height: 0.72rem;
  16. padding-left: 0.2rem;
  17. }

Carousel走马灯 - 图1

API ( 适用平台:WEB、React-Native )

参数说明类型默认值
selectedIndex手动设置当前显示的索引number0
dots是否显示面板指示点Booleantrue
vertical垂直显示(web 为内容,rn 为 pagination)Booleanfalse
autoplay是否自动切换Booleanfalse
infinite是否循环播放Booleanfalse
afterChange切换面板后的回调函数(current: number): void
easing (web only)动画效果Stringlinear
beforeChange (web only)切换面板前的回调函数(from: number, to: number): void
onScrollBeginDrag (rn only)见 react-native scrollView onScrollBeginDrag(): void
bounces (rn only)见 react-native scrollView bouncesBooleantrue
更多参数可参考:https://github.com/FormidableLabs/nuka-carousel