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=" ...
随机推荐
- denyhost安装脚本
#!/bin/bashDENYHOSTS=DenyHosts-2.6.tar.gzDENYHOSTS_VERSION=DenyHosts-2.6DENYHOSTS_URL=http://192.168 ...
- MFC模块状态(一)
先看一个例子: 1.创建一个动态链接到MFC DLL的规则DLL,其内部包含一个对话框资源.指定该对话框ID如下: #define IDD_DLL_DIALOG 2000 ...
- spring整合redis之hello
1.pom.xml文件 <dependencies> <!-- spring核心包 --> <dependency> <groupId>org.spri ...
- web-day4
第4章WEB04- JQuery篇 今日任务 使用JQuery完成页面定时弹出广告 使用JQuery完成表格的隔行换色 使用JQuery完成复选框的全选效果 使用JQuery完成省市联动效果 使用JQ ...
- java基础-day30
第07天 MySQL数据库 今日内容介绍 u 多表关系实战练习 u 多表查询 u SQL语句的练习 第1章 多表关系实战练习 1.1 多表关系--实战1--省和市 1.1.1 需求分析 在数据库 ...
- Python3 安装 PyQt5 -pycharm 环境搭建
执行命令: pip3 install PyQt5 PyQt5+python3+pycharm开发环境配置 1.下载PyQt 官方网站:http://www.riverbankcomputing.c ...
- codeforces 891 b
B. Gluttony time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- hdu 5091 给定矩形覆盖尽量多点 扫描线+线段树
http://acm.hdu.edu.cn/showproblem.php?pid=5091 给你10000以内的敌舰的坐标(即分别为x,y),要求用W*H的矩形去围住一个区域,使得这个区域内的敌舰最 ...
- centos下添加epel源
RHEL以及他的衍生发行版如CentOS.Scientific Linux为了稳定,官方的rpm repository提供的rpm包往往是很滞后的,当然了,这样做这是无可厚非的,毕竟这是服务器版本,安 ...
- SQL Server 2008 表分区的含义
https://www.cnblogs.com/knowledgesea/p/3696912.html 继续看这个文档 http://www.360doc.com/content/16/0104/11 ...