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");
}
}