【轮播图】

项目场景:

提示:这里简述项目相关背景:

轮播图自适应底图大小不会超出,还能保证图片保持尺寸


实现方法

<Carousel autoplay={true} dots={false} style={{float: 'left',width: '90%'}} className={'shadow-box'} pauseOnHover={false} autoplaySpeed={5000} fade={true}>
                {
                  lunbo1.map((i:any,index) => {
                    return (
                      <div key={index}>
                        <div className={'img'} style={{backgroundImage:`url(${i.src})`}}>
                          <img src='https://www.sztu.edu.cn/static2022/upload/energeticc.png' className={'img-block'} alt='' />
                        </div>
                      </div>
                    )
                  })
                }
              </Carousel>


.shadow-box {
  background-color: rgba(255, 255, 255, 0);
  overflow: hidden;
  position: relative;
  z-index: 2; /* 确保 Carousel 组件在 img 元素之上 */
}

.img {
  position: relative; /* 不需要改变,因为你希望背景图片相对于 Carousel 容器定位 */
  overflow: hidden;
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  background-color: #000; /* 当背景图片未加载时显示的颜色 */
}
.img img {
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  padding: 0;
  border: 0;
  width: 100%;
  height: auto;
  border: none;
}

.img-block {
  display: block;
  width: 100%;
  height: auto;
}

分析:

使用ant design的Carousel组件,通过设置背景图的方式,放置轮播图

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值