Skip to content

基础版

/exp/swiper/base/
html
<div class="swiper-base">
  <div class="swiper-base__slick">
    <a class="slick-item">
      <img
        src="https://mc.kurogames.com/static4.0/assets/weilinai-4a35ce55.png"
      />
    </a>

    <a class="slick-item">
      <img
        src="https://mc.kurogames.com/static4.0/assets/shorekeeper-36913543.png"
      />
    </a>

    <a class="slick-item">
      <img src="https://mc.kurogames.com/static4.0/assets/lupa-1e612111.webp" />
    </a>
  </div>

  <button class="swiper-base-prev"></button>
  <button class="swiper-base-next"></button>
</div>
ts
$(function () {
  const slickBaseSwiper = $(".swiper-base .swiper-base__slick");

  //@ts-ignore
  slickBaseSwiper.slick({
    autoplay: true,
    autoplaySpeed: 3000,
    arrows: false,
    infinite: true,
    dots: true,
    dotsClass: "swiper-base-dots",
  });

  $(".swiper-base-prev").click(function () {
    //@ts-ignore
    slickBaseSwiper.slick("slickPrev");
  });

  $(".swiper-base-next").click(function () {
    //@ts-ignore
    slickBaseSwiper.slick("slickNext");
  });
});
less
@import "../../my/reset.less";

.swiper-base {
  margin: 40px auto;
}

.swiper-base {
  width: 500px;
  height: 300px;

  position: relative;
  overflow: hidden;

  .swiper-base__slick {
    .slick-item {
      display: block;

      img {
        width: 500px;
        height: 300px;
        object-fit: cover;
      }
    }
  }

  .swiper-base-prev {
    width: 34px;
    height: 58px;

    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);

    background-color: rgba(0, 0, 0, 0.2);
    background-image: url("./icon/left.png");
    background-size: 24px 24px;
    background-position: center center;
    background-repeat: no-repeat;
  }

  .swiper-base-next {
    width: 34px;
    height: 58px;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);

    background-color: rgba(0, 0, 0, 0.2);
    background-image: url("./icon/right.png");
    background-size: 24px 24px;
    background-position: center center;
    background-repeat: no-repeat;
  }
}

.swiper-base-dots {
  position: absolute;
  bottom: 24px;
  width: 100%;

  display: flex;
  display: -ms-flexbox;

  justify-content: center;
  -ms-flex-pack: center;

  align-items: center;
  -ms-flex-align: center;

  li {
    width: 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    font-size: 12px;
    color: rgb(255, 255, 255);
    cursor: pointer;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.35);

    transition: all 0.5s linear;
    margin-left: 8px;
  }

  .slick-active {
    background-color: #cc0000;
  }
}