vue实现循环滚动图片(多图片轮播)

 效果(循环滚动,可切换方向):

 轮播组件BaseSwiper.vue:

<template>
    <div class="swiperBox">
        <img class="imgLeft" @click="clickLeft" src="../../../assets/img/左.png" alt="">
        <img class="imgRight" @click="clickRight" src="../../../assets/img/右.png" alt="">
        <div id="swiper">
            <div class="imgBox">
                <div class="imgDiv" v-for="(item,index) of imgList" :key="in
  • 11
    点赞
  • 72
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论
实现vue的轮图无缝滚动,可以使用vue-awesome-swiper插件。以下是实现步骤: 1.安装vue-awesome-swiper插件 ``` npm install vue-awesome-swiper --save ``` 2.引入插件 在需要使用轮图的组件中引入swiper和swiper样式: ```javascript import { swiper, swiperSlide } from 'vue-awesome-swiper' import 'swiper/dist/css/swiper.css' ``` 3.编写轮图组件 ```html <template> <swiper :options="swiperOption" ref="mySwiper"> <swiper-slide v-for="(item, index) in list" :key="index"> <!-- 轮图内容 --> </swiper-slide> </swiper> </template> <script> export default { data() { return { list: [], // 轮图数据 swiperOption: { // swiper配置 loop: true, // 开启循环模式 navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } } } }, components: { swiper, swiperSlide }, mounted() { this.$nextTick(() => { this.$refs.mySwiper.$swiper.update() // 更新swiper }) } } </script> ``` 4.添加css样式 ```css .swiper-slide { position: relative; width: 100%; height: 100%; overflow: hidden; } .swiper-slide img { width: 100%; height: 100%; display: block; } .swiper-slide::before { content: ""; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background-color: #fff; z-index: 1; opacity: 0.8; } .swiper-slide::after { content: ""; position: absolute; top: 0; right: -100%; width: 100%; height: 100%; background-color: #fff; z-index: 1; opacity: 0.8; } .swiper-slide-duplicate::before { left: 100%; } .swiper-slide-duplicate::after { right: 100%; } ``` 这样就可以实现vue的轮图无缝滚动了。
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

suoh's Blog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值