欢迎来到代码驿站!

vue

当前位置:首页 > 网页前端 > vue

基于Vue3实现旋转木马动画效果

时间:2022-08-26 09:12:55|栏目:vue|点击:

做的比较丑 最后图片

本来打算用vue-carousel-3d这个组件的,但是这个组件一直报源码错误,修改了半天也没有解决

效果图

实现代码

使用了swiper组件

html部分代码

  <div class="swiper-container swiper1" style="height: 650px;width: 1500px">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <div class="box-card">
            <img src="../../assets/homeScroll/trunkRoad.png" alt="" />
            <br>
            <el-button type="primary" @click="jumpUrl1">国省干道</el-button>
          </div>
        </div>
        <div class="swiper-slide">
          <div class="box-card">
            <img src="../../assets/homeScroll/bikeSystem.png" alt="" />
            <br>
            <el-button type="primary" @click="jumpUrl2">自行车系统</el-button>
          </div>
        </div>
        <div class="swiper-slide">
          <div class="box-card">
            <img src="../../assets/homeScroll/bridge.png" alt="" />
            <br>
            <el-button type="primary">桥梁</el-button>
          </div>
        </div>
        <div class="swiper-slide">
          <div class="box-card">
            <img src="../../assets/homeScroll/cityExpressway.png" alt="" />
            <br>
            <el-button type="primary">城市快速路</el-button>
          </div>
        </div>
        <div class="swiper-slide">
          <div class="box-card">
            <img src="../../assets/homeScroll/resultIntegration.png" alt="" />
            <br>
            <el-button type="primary" @click="jumpUrl3">结果集成</el-button>
          </div>
        </div>
        <div class="swiper-slide">
          <div class="box-card">
            <img src="../../assets/homeScroll/trunkRoad.png" alt="" />
            <br>
            <el-button type="primary">高速公路</el-button>
          </div>
        </div>
        <div class="swiper-slide">
          <div class="box-card">
            <img src="../../assets/homeScroll/bikeSystem.png" alt="" />
            <br>
            <el-button type="primary" @click="jumpUrl2">自行车系统</el-button>
          </div>
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <!--      <div class="swiper-pagination"></div>-->

      <div class="swiper-button-prev"></div>
      <!--左箭头。如果放置在swiper-container外面,需要自定义样式。-->
      <div class="swiper-button-next"></div>
      <!--右箭头。如果放置在swiper-container外面,需要自定义样式。-->
    </div>

js部分代码

import { onMounted } from "vue";
import Swiper, {
  Autoplay,
  EffectCoverflow,
  EffectCube,
  Pagination,
  Navigation,
} from "swiper";
Swiper.use([Autoplay, EffectCoverflow, EffectCube, Pagination, Navigation]);
// swiper-bundle.min.css 决定了小圆点和左右翻页,如果不需要可以不引用
import "swiper/swiper-bundle.min.css";
// swiper.less/sass/css 决定了基础的样式
import "swiper/swiper.min.css";

export default {
  setup() {
    onMounted(() => {
      new Swiper(".swiper1", {
        // 循环
        loop: true,
        //每张播放时长3秒,自动播放
        spaceBetween: 40,
        effect: "coverflow",
        grabCursor: true,
        centeredSlides: true,
        slidesPerView: 5,
        // autoplay: {
        //   delay: 3000,
        //   stopOnLastSlide: false,
        //   disableOnInteraction: false,
        // },
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
        coverflowEffect: {
          rotate: 0,
          stretch: 0,
          depth: 100,
          modifier: 1,
          slideShadows: false,
        }
      });
    });
  },
  methods:{
    jumpUrl1(){
      const routeData = this.$router.replace({
        path: '/index',
      });
      // window.open(routeData.href, '_blank');
    }
  }
}

上一篇:vue3.0语法糖内的defineProps及defineEmits解析

栏    目:vue

下一篇:vue element和nuxt的使用技巧分享

本文标题:基于Vue3实现旋转木马动画效果

本文地址:http://www.codeinn.net/misctech/211917.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有