当前位置:网站首页>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![]()
边栏推荐
- Image recognition from zero to write DNF script key points
- d合并json
- 买母婴产品先来京东“券民空间站”抢券!大牌好物低至5折
- 厌倦了安装数据库?改用 Docker
- Speech Synthesis Model Cheat Sheet (1)
- 非关系型数据库MongoDB简介和部署
- MySql查询某个时间段内的数据(前一周、前三个月、前一年等)
- 思源笔记 本地存储无使用第三方同步盘,突然打不开文件。
- Strict feedback nonlinear systems based on event trigger preset since the immunity of finite time tracking control
- NLP常用Backbone模型小抄(1)
猜你喜欢
随机推荐
js基础知识整理之 —— 判断语句和三元运算符
redis的学习笔记
MDL 内存描述符链表
脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3
APT level comprehensive free kill with Shell
函数:计算组合数
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
d合并json
VMware workstation 程序启动慢
What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
No code development platform data ID introductory tutorial
vscode 自定义快捷键——设置eslint
语音合成模型小抄(1)
测试人生 | 阿里实习 90 天:从实习生的视角谈谈个人成长
秒懂网络拓扑中的下一跳地址
典型相关分析CCA计算过程
Based on two levels of decomposition and the length of the memory network multi-step combined forecasting model of short-term wind speed
合并两个excel表格工具
Let's talk about the charm of code language
简单聊聊MySQL中的六种日志









