swiper4-vue 不使用loop,由最后一张跳到第一张
<template>
<div class="swiper-box">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="(item, index) in slides" :key="index">
<img :src="item" :data-index="index">
</div>
</div>
</div>
<div class="swiper-add" id="add" @click="clickAdd">
<img src="../../assets/left/add.png">
</div>
<div class="swiper-text" >
<div>- 123 -</div>
<div>name<span></span><span>5星</span></div>
</div>
</div>
</template>
<script>
import Swiper from '../../../static/swiper.min.js';
import '../../../static/swiper.min.css';
export default {
props: {
slides: {
type: Array,
}
},
data() {
return {
mySwiper: {},
status: 1,
}
}, methods:{
initSwiper(){
this.mySwiper = new Swiper('.swiper-container', {
// loop: true,
// loopFillGroupWithBlank: true,
// grabCursor: true,
queueEndCallbacks: true,
centeredSlides: true,//
allowTouchMove: false, //不允许触摸滑动
slidesPerView: 3,//设置slider容器能够同时显示的slides数量(carousel模式)。可以设置为数字(可为小数,小数不可loop),或者 'auto'则自动根据slides的宽度来设定数量。loop模式下如果设置为'auto'还需要设置另外一个参数loopedSlides。
slidesPerGroup: 1,
// watchSlidesProgress : true,
// watchSlidesVisibility : true,
spaceBetween: 20,
// slidesOffsetBefore: 100,
// slidesOffsetAfter : 300,
initialSlide: 0,
observer:true,
observerParents:true, });
this.$store.dispatch('getSwiperValue', this.mySwiper);
var self = this;
this.mySwiper.on('slideChangeTransitionEnd', function (swiper) { // 滑动之后执行
var $img = document.querySelector('.swiper-slide-active > img');
self.$store.dispatch('getSwiperIndex', $img.getAttribute('data-index')); // 得到第几张图片
console.log($img.getAttribute('data-index'), this.slides.length - 1);
if(this.isEnd) { //最后一个
self.status = 2 // 修改状态
}
});
},
//点击下一张
clickAdd(){
if(this.status === 2){
this.mySwiper.slideTo(0, 1000, false); // 回跳到第一个
this.status = 1;
this.$store.dispatch('getSwiperIndex', 0); // 修改值,第一张图片
} else {
this.mySwiper.slideNext(); // 下一张
}
}, },
mounted() {
this.initSwiper();
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less">
.swiper-box {
position: relative;
width: 408px;
height: 248px;
background: url('../../assets/left/bg.png') no-repeat;
background-size: 100% auto;
}
.swiper-container {
width: 300px;
margin-left: 50px;
}
.swiper-slide {
text-align: center;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
.swiper-add {
position: absolute;
right: 12px;
top: 82px;
}
.swiper-add img {
width: 40px;
height: 42px;
} .swiper-text {
color: #ffffff;
text-align: center;
line-height:32px;
position: absolute;
left: 50%;
top: 78%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
}
.swiper-text div:last-child {
color: #43FFD2;
font-size: 18px;
vertical-align: middle;
}
.swiper-text span:first-child {
display: inline-block;
width: 23px;
height: 26px;
margin: 0 4px 0 12px;
vertical-align: middle;
background: url('../../assets/left/level.png') no-repeat;
background-size: 100% auto;
}
.swiper-text span:last-child {
font-size: 12px;
vertical-align: middle;
}
.swiper-wrapper {
padding-top: 44px;
height: 110px;
} .swiper-slide img {
width: 80px;
height: 80px;
}
.swiper-slide-active img {
width: 110px;
height: 110px;
} </style>
swiper4-vue 不使用loop,由最后一张跳到第一张的更多相关文章
- vue使用vue-router beforEach实现判断用户登录跳转路由筛选
vue使用vue-router beforEach实现判断用户登录跳转路由筛选 :https://www.colabug.com/3306814.html 在开发webApp的时候,考虑到用户体验,经 ...
- vue常用操作及学习笔记(路由跳转及路由传参篇)
路由跳转 - 超链接方式跳转 html: <div id="app"> <h1>Hello App!</h1> <p> <!- ...
- Vue 实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案
Vue实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案 by:授客 QQ:1033553122 开发环境 Win 10 Vue 2.9.6 node-v ...
- Vue router拦截 如果用户并未登录直接跳转到登录界面(最简单的cookie演示)
router.beforeEach(function(to,from,next){ console.log('路由拦截') console.log(to.name) console.log(from. ...
- Vue.js中,如何自己维护路由跳转记录?
在Vue的项目中,如果我们想要做返回.回退操作时,一般会调用router.go(n)这个api,但是实际操作中,使用这个api有风险,就是会让用户跳出当前应用,因为它记录的是浏览器的访问记录,而不是你 ...
- vue多个路由复用同一个组件的跳转问题(this.router.push)
因为router-view传参问题无法解决,比较麻烦. 所以我采取的是@click+this.router.push来跳转 但是现在的问题是跳转后,url改变了,但是页面的数据没有重新渲染,要刷新才可 ...
- 小白学习vue第五天(理解使用组件开发,组件第一弹)
组件怎么从创建到使用? 第一步创建组件构造器对象 感觉个人理解就是创建一个模板,和创建MongoDB数据模板相似 const cpnC = Vue.extend({ template: ` <d ...
- vue多个数据不一样的表格导出到同一张excel里面
刚来公司第二天, 甩了个需求, 把两个不同表格的数据 导出到同一个excel中 ........额,好吧 你要说,两个表格数据差不多, 直接合并数据导出就行: async function getDa ...
- vue 自动识别PC、移动端,并跳转到对应页面
app.vuehead中添加 <!--自动识别PC.移动--> <script src="static/js/uaredirect.js" type=" ...
随机推荐
- pat树之专题(30分)
(好好复习是王道) 1115. Counting Nodes in a BST (30) 分析:简单题——将bst树构造出来,然后给每个节点打上高度.最后求出树的高度.然后count树高的节点数加上树 ...
- hadoop hive组件介绍及常用cli命令
Hive架构图 Hive产生原因 1 关系型数据库以产生多年sql成熟 2 简化开发降低成本 3 java成员可编写udf函数 Hive是什么 Hive是基于hadoop的一个数据库工具,使用Hql作 ...
- Window下同一台服务器部署多个tomcat服务简易教程
第一步:解压两份tomact 分别为tomactserver01和tomactserver02文件夹 第二.配置tomact的环境变量 分别为 第三步:分别修改tomact的bin目录下的catali ...
- Nodejs入门【转载】保留备用
关于 本书致力于教会你如何用Node.js来开发应用,过程中会传授你所有所需的“高级”JavaScript知识.本书绝不是一本“Hello World”的教程. 状态 你正在阅读的已经是本书的最终版. ...
- sea.js教程
转载自:http://blog.codinglabs.org/articles/modularized-javascript-with-seajs.html 前言 SeaJS是一个遵循CommonJS ...
- Flash网页小游戏开发教程
架设服务器 地图 程序员
- Leetcode-448. Find All Numbers Disappeared in an Array(solve without extra space easy)
Given an array of integers where 1 ≤ a[i] ≤ n (n= size of array), some elements appear twice and oth ...
- EndNote安装
下载地址:https://download.csdn.net/download/noticeable/10283841 EndNote X8.1是一款功能强大的文献管理软件,软件在x8版本中继承了国际 ...
- java poi 合并单元格
java poi 合并单元格 2017年03月29日 16:39:01 翠烟你懊恼 阅读数:26561 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.n ...
- Stein算法求最大公约数
首先引进一个符号:gcd是greatest common divisor(最大公约数)的缩写,gcd( x,y ) 表示x和y的最大公约数.然后有一个事实需要了解:一个奇数的所有约数都是奇数.这个很容 ...