当前位置:网站首页>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![]()
边栏推荐
- FastCorrect:语音识别快速纠错模型丨RTC Dev Meetup
- Controller层代码这么写,简洁又优雅!
- 数据库审计 - 网络安全的重要组成部分
- NLP常用Backbone模型小抄(1)
- APT级全面免杀拿Shell
- 学习Autodock分子对接
- The CTF command execution subject their thinking
- Pytest配置项-pytest.ini
- ROS2初级知识(9):bag记录过程数据和重放
- What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
猜你喜欢
随机推荐
d合并json
Strict feedback nonlinear systems based on event trigger preset since the immunity of finite time tracking control
我们来浅谈代码语言的魅力
00 -- jieba分词
2022第十一届财经峰会:优炫软件斩获双项大奖
Day117.尚医通:生成挂号订单模块
threejs 动态调整相机位置,使相机正好能看到对象
Token、Redis实现单点登录
scala 集合通用方法
精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队
MySQL最大建议行数2000w, 靠谱吗?
APT级全面免杀拿Shell
# DWD层及DIM层构建## ,220801 ,
微信小程序(一)
CTF命令执行题目解题思路
[论文总结] 深度学习在农业领域应用论文笔记10
厌倦了安装数据库?改用 Docker
最新真实软件测试面试题分享,收藏了还怕进入不了大厂?
基于飞腾平台的嵌入式解决方案案例集 1.0 正式发布!
雷克萨斯lm的安全性如何?





![Yocto系列讲解[实战篇]85 - 制作ubi镜像和自动挂载ubifs文件系统](/img/96/beb34ce07f1e4c0fe932359e42e5c6.png)



