当前位置:网站首页>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![]()
边栏推荐
猜你喜欢
随机推荐
2022第十一届财经峰会:优炫软件斩获双项大奖
DownMusic总结记录
函数:计算组合数
1 - vector R language self-study
辅助脚本开发之旅
厌倦了安装数据库?改用 Docker
Yocto系列讲解[实战篇]85 - 制作ubi镜像和自动挂载ubifs文件系统
记一次mysql查询慢的优化历程
智能电视竞争白热化,利用小程序共建生态突围
无代码开发平台表单样式设置步骤入门课程
在软件测试行业近20年的我,再来和大家谈谈今日的软件测试
centos7安装mysql8
ssm整合(三)Controller 和 视图层编写
CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
Find My技术|智能防丢还得看苹果Find My技术
C语言函数详解(2)【函数参数——实际参数(实参)&形式参数(形参)】
Strict feedback nonlinear systems based on event trigger preset since the immunity of finite time tracking control
AcWing 2983. 玩具
Cholesterol-PEG-Acid,胆固醇-聚乙二醇-羧基保持在干燥、低温环境下
ZCMU--5230: 排练方阵(C语言)









