react项目网页轮播使用Swiper插件,img适配不同分辨率图片不被压缩

import SwiperCore, {Pagination} from 'swiper';
import {Swiper, SwiperSlide} from "swiper/react";
import "swiper/swiper.less";
import "swiper/swiper-bundle.min";
import "swiper/swiper-bundle.min.css";
import "swiper/components/pagination/pagination.min.css";
<div className="slogan-box">
  <Swiper pagination={true} loop={true} className="mySwiper">
    {bannerText.map((e, i) => {
      return (
        <SwiperSlide key={i}>
          <div className={i===0?'swiperImg':i===1?'swiperImg swiperImg1':'swiperImg swiperImg2'}></div>
        </SwiperSlide>
      );
    })}
  </Swiper>
</div>

把轮播图片设置成背景图,数据轮播根据对应的下标切换背景图就可以了

.mySwiper {
  position: relative;
  height: 660px;
  min-width: 1200px;
  margin: 0 auto;

  .swiper-pagination-bullets {
    bottom: 120px !important;
    width: 1200px;
    text-align: left;
    left: 50%;
    transform: translateX(-50%);

    .swiper-pagination-bullet {
      width: 50px;
      height: 4px;
      background: #FFFFFF;
      border-radius: 2px;
    }

    .swiper-pagination-bullet-active {
      width: 50px;
      height: 4px;
      background: #F37400 !important;
      border-radius: 2px;
    }
  }

  .swiperImg {
    background-image: url("../../assets/image/banner1.gif");
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 660px;
    background-position: center top;
    background-size: auto 100%;
    background-repeat: no-repeat;
  }

  .swiperImg1 {
    background-image: url("../../assets/image/banner2.gif");
  }

  .swiperImg2 {
    background-image: url("../../assets/image/banner3.gif");
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值