当前位置:网站首页>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 height
When 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 preview
Using 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
边栏推荐
- Token、Redis实现单点登录
- 微信小程序实现lot开发09 接入微信登录
- 【代码扫描修复】MD5加密弱HASH漏洞
- 停止使用 Storyboards 和 Interface Builder
- Towards a General Purpose CNN for Long Range Dependencies in ND
- CTF命令执行题目解题思路
- Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
- No-code development platform form styling steps introductory course
- 用了 TCP 协议,数据一定不会丢吗?
- qt静态编译出现Project ERROR: Library ‘odbc‘ is not defined
猜你喜欢
脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3
CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
基于飞腾平台的嵌入式解决方案案例集 1.0 正式发布!
非关系型数据库MongoDB简介和部署
The latest real software test interview questions are shared. Are you afraid that you will not be able to enter the big factory after collecting them?
VMware workstation program starts slowly
CAS:474922-22-0,DSPE-PEG-MAL,磷脂-聚乙二醇-马来酰亚胺科研试剂供应
用了 TCP 协议,数据一定不会丢吗?
markdown语法
2022第十一届财经峰会:优炫软件斩获双项大奖
随机推荐
基于奇异谱分析法和长短时记忆网络组合模型的滑坡位移预测
漫画:怎么证明sleep不释放锁,而wait释放锁?
MySQL 与InnoDB 下的锁做朋友 (四)行锁/记录锁
ZCMU--5230: 排练方阵(C语言)
centos7安装mysql5.7步骤(图解版)
centos7安装mysql8
最近公共祖先(LCA)学习笔记 | P3379 【模板】最近公共祖先(LCA)题解
我们来浅谈代码语言的魅力
D with json
DownMusic总结记录
Numpy数组中d[True]=1的含义
centos7安装mysql5.7
【斯坦福计网CS144项目】Lab5: NetworkInterface
I have been in the software testing industry for nearly 20 years, let me talk to you about today's software testing
程序员如何优雅地解决线上问题?
Kubernetes 进阶训练营 网络
js基础知识整理之 —— 全局作用域
2022暑假牛客多校1 (A/G/D/I)
微信小程序实现lot开发09 接入微信登录
Cholesterol-PEG-Acid,胆固醇-聚乙二醇-羧基保持在干燥、低温环境下