基于antd实现一个轮播图

关于antd的使用这里就不多说了,前面已经写过了,从零开始学习React-引入Ant Design 组件(八):https://www.jianshu.com/p/e7e905d89673,现在为了对组件的熟悉,来根据文档写一个常见的轮播图吧。

1:首先生成一个空组件模板

import React, { Component } from 'react';
class Banner extends Component {
    constructor(props) {
        super(props);
        //react定义数据
        this.state = {
        }
    }
    render() {
        return (
            <div>
                <h2>我是轮播图界面</h2>                           
            </div>
        )
    }
}
export default  Banner;

2:引入

import { Carousel } from 'antd';

3:文档
https://ant.design/components/carousel-cn/

4:样式
在tab.css里面写好样式,并且在组件里面引入

import '../asset/css/tab.css'

tab.css内容如下


.ant-carousel .slick-slide {
    text-align: center;
    height: 360px;
    line-height: 160px;
    background: #364d79;
    overflow: hidden;
  }
  
  .ant-carousel .slick-slide h3 {
    color: #fff;
  }

  .ant-carousel .slick-slide h3  img{
   width:100%;
   height:100%;
  }

5:参考代码

import React, { Component } from 'react';
import { Carousel } from 'antd';
import '../asset/css/tab.css'

class Banner extends Component {
    constructor(props) {
        super(props);
        //react定义数据
        this.state = {
        }
    }
    render() {
        return (
            <Carousel autoplay>
                <div>
                    <h3><img src={require('../asset/images/7.jpg')}  alt="logo" />></h3>
                </div>
                <div>
                    <h3><img src={require('../asset/images/8.jpg')}  alt="logo" />></h3>
                </div>
                <div>
                    <h3><img src={require('../asset/images/9.jpg')}  alt="logo" />></h3>
                </div>
                <div>
                    <h3><img src={require('../asset/images/10.jpg')}  alt="logo" />></h3>
                </div>
            </Carousel>
        )
    }
}
export default Banner;

动态的轮播图效果如下:

 
5640239-97ac9cd89866da46.png
 

原文作者:祈澈姑娘 技术博客:https://www.jianshu.com/u/05f416aefbe1
90后前端妹子,爱编程,爱运营,文艺与代码齐飞,魅力与智慧共存的程序媛一枚,欢迎关注【编程微刊】公众号。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值