当前位置:网站首页>vant-swipe adaptive picture height + picture preview
vant-swipe adaptive picture height + picture preview
2022-08-03 01:33:00 【GG bond】
vant-swipe adaptive image height + image preview
1.vant-swipe adaptive image heightWhen the image heights of the carousel images are not the same, if the height is not set, van-swipe-item will take the height of the highest image as the height. If the height of other images is lower than this height, the bottom will be blank, affecting thebeautiful

Solution: Use the height (slider height) and change event of Swipe Props to re-acquire the image height and assign it to the slider height every time the image is switched.
//Getasync mounted(){let res= await this.getImgSize(this.imgs[0])this.height=res.height/(res.width/375)},methods:{// Get the image size from the url of the imagegetImgSize(url) {return new Promise((resolve, reject) => {let img = new Image()img.src = urlimg.onload = () => {resolve({width: img.width,height: img.height})}})}//swipe switch listener eventasync onChange(index) {let res= await this.getImgSize(this.imgs[index])// Image fixed width 100vwthis.height=res.height/(res.width/375)},}2. Image previewUsing vant's ImagePreview function, you need to use swipe's autoplay. When autoplay=0, stop playing; when the picture enters the preview, turn off autoplay, and when the preview ends, jump to the corresponding picture (you need to temporarily close the carouselanimation, otherwise it will flash by), start playing automatically
//PreviewshowImage(i){// Preview turns off carousel scrollingthis.autoplay=0ImagePreview({images: this.imgs,// starting image positionstartPosition: i,overlayStyle:{background: '#000'},//When the preview image is closed - the image is the starting image of the carousel imageonClose:res=> {//The method of carousel image, jump to the corresponding imagethis.$refs.vantSwiper.swipeTo(res.index,{immediate:true //Turn off the carousel switching effect})this.autoplay=2000},});},3. All codes![]()
边栏推荐
猜你喜欢

Jmeter secondary development to realize rsa encryption

mPEG-Cholesterol,mPEG-CLS,甲氧基-聚乙二醇-胆固醇可用于脂质体制备

脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3

js基础知识整理之 —— 获取元素和命名规范

Week 7 CNN Architectures - LeNet-5、AlexNet、VGGNet、GoogLeNet、ResNet

CentOS7 安装MySQL 图文详细教程

MySQL 与InnoDB 下的锁做朋友 (四)行锁/记录锁

在软件测试行业近20年的我,再来和大家谈谈今日的软件测试

markdown语法

数据库主键一定要自增吗?有哪些场景不建议自增?
随机推荐
【C语言】带头双向循环链表(list)详解(定义、增、删、查、改)
CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
Week 7 - Distributional Representations
Cholesterol-PEG-Amine,CLS-PEG-NH2,胆固醇-聚乙二醇-氨基脂两亲性脂质衍生物
测试人生 | 阿里实习 90 天:从实习生的视角谈谈个人成长
AcWing 2983. 玩具
C语言函数详解(2)【函数参数——实际参数(实参)&形式参数(形参)】
DownMusic总结记录
scala 集合通用方法
threejs 动态调整相机位置,使相机正好能看到对象
微信小程序实现lot开发09 接入微信登录
停止使用 Storyboards 和 Interface Builder
Merge two excel spreadsheet tools
00 -- jieba分词
思源笔记 本地存储无使用第三方同步盘,突然打不开文件。
centos7安装mysql5.7
秒懂网络拓扑中的下一跳地址
mysql根据多字段分组——group by带两个或多个参数
非关系型数据库MongoDB简介和部署
Test | ali internship 90 days in life: from the perspective of interns, talk about personal growth