swiper根据图片切换不同的背景色
JS:
var mySwiper = new Swiper('.swiper-container', { autoplay: true, //可选选项,自动滑动 loop: true, paginationClickable: true, navigation: { nextEl: ' .swiper-button-next ', prevEl: ' .swiper-button-prev ', }, autoplay: { delay: 3000, }, pagination: { el: ' .swiper-pagination ', }, on: { slideChangeTransitionStart() { $(".m-slide-container").css("background", $('#banner-image' + this.realIndex).attr("data-bg_color")) } } });
HTML:
<div class="m-slide-container"> <div class="swiper-container" style="text-align: center;"> <div class="swiper-wrapper"> <div class="swiper-slide"> <a href="{$banner['url']}" target="_blank"> <img class="banner-img" id="banner-image{$+1}" data-bg_color="{{$banner["bg_color"]}}" class="banner-img" src="{$banner['thumb_url'])}" alt="{{$banner['title']}}"> </a> </div> </div> <div class="swiper-button-prev swiper_btn swiper-button-white" style="margin-left: 10px;opacity:0.3;"> </div> <div class="swiper-button-next swiper_btn swiper-button-white" style="margin-right: 10px;opacity:0.3;"> </div> </div> </div>