swiper3D覆盖流的实现方法 vue3+nuxt3

<template>
  <div class="swiper-container">
    <client-only>
      <Swiper
        :effect="'coverflow'"
        :grab-cursor="true"
        :centered-slides="true"
        :slides-per-view="slidesPerView"
        :coverflow-effect="{
          rotate: 30,
          stretch: 50,
          depth: 100,
          modifier: 1,
          slideShadows: true,
        }"
        :loop="true"
        :pagination="{
          clickable: true
        }"
        :navigation="true"
        :modules="modules"
        :breakpoints="breakpoints"
      >
        <SwiperSlide>
          <img src="../assets/imgs/cover/1.png" alt="图片1">
        </SwiperSlide>
        <SwiperSlide>
            <img src="../assets/imgs/cover/2.png" alt="图片1">
        </SwiperSlide>
        <SwiperSlide>
            <img src="../assets/imgs/cover/3.png" alt="图片1">
        </SwiperSlide>
        <SwiperSlide>
            <img src="../assets/imgs/cover/4.png" alt="图片1">
        </SwiperSlide>
        <SwiperSlide>
            <img src="../assets/imgs/cover/1.png" alt="图片1">
        </SwiperSlide>
        <SwiperSlide>
            <img src="../assets/imgs/cover/1.png" alt="图片1">
        </SwiperSlide>
        <SwiperSlide>
            <img src="../assets/imgs/cover/1.png" alt="图片1">
        </SwiperSlide>
        <SwiperSlide>
            <img src="../assets/imgs/cover/1.png" alt="图片1">
        </SwiperSlide>
      </Swiper>
    </client-only>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { Swiper, SwiperSlide } from 'swiper/vue'
import { EffectCoverflow, Navigation, Pagination } from 'swiper/modules'
import 'swiper/css'
import 'swiper/css/effect-coverflow'
import 'swiper/css/navigation'
import 'swiper/css/pagination'

const modules = [EffectCoverflow, Navigation, Pagination]

const breakpoints = {
  320: {
    slidesPerView: 2,
    spaceBetween: 10
  },
  // 当屏幕宽度 >= 768px
  768: {
    slidesPerView: 3,
    spaceBetween: 20
  },
  // 当屏幕宽度 >= 1024px
  1024: {
    slidesPerView: 4,
    spaceBetween: 30
  }
}

// 默认幻灯片数量
const slidesPerView = ref(3)
</script>

<style scoped>
.swiper-container {
  width: 100%;
  height: 400px;
  margin: 50px auto;
}

.swiper-slide {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
}

.swiper-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* 移动端适配 */
@media (max-width: 767px) {
  .swiper-container {
    width: 95%;
    height: 250px;
    margin: 30px auto;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .swiper-container {
    width: 90%;
    height: 200px;
    margin: 40px auto;
  }
}

@media (min-width: 1024px) {
  .swiper-container {
    width: 100%;
    height: 400px;
    margin: 50px auto;
  }
}
</style>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值