当前位置:网站首页>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
![]()
边栏推荐
- 基于飞腾平台的嵌入式解决方案案例集 1.0 正式发布!
- Find My技术|智能防丢还得看苹果Find My技术
- TCP三次握手与四次挥手
- 虚拟内存 virualmemory
- CKAN教程之将 Snowflake 连接到 CKAN 以发布到开放数据门户
- 非关系型数据库MongoDB简介和部署
- Towards a General Purpose CNN for Long Range Dependencies in ND
- 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?
- 聚乙二醇衍生物4-Arm PEG-DSPE,四臂-聚乙二醇-磷脂
- ssm整合(三)Controller 和 视图层编写
猜你喜欢
随机推荐
令人心动的AI综述(1)
CKAN教程之在 AWS 上部署 CKAN 应用程序
Let's talk about the charm of code language
js基础知识整理之 —— 获取元素和命名规范
Token、Redis实现单点登录
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?
执子手,到永恒
js基础知识整理之 —— 五种输出方式
js基础知识整理之 —— 字符串
雷克萨斯lm的安全性如何?
C语言函数详解(2)【函数参数——实际参数(实参)&形式参数(形参)】
mysql根据多字段分组——group by带两个或多个参数
漫画:怎么证明sleep不释放锁,而wait释放锁?
基于STM32的FLASH读写实验含代码(HAL库)
合并两个excel表格工具
2022杭电多校第一场(K/L/B/C)
APT level comprehensive free kill with Shell
学习基因富集工具DAVID(3)
Controller层代码这么写,简洁又优雅!
Cholesterol-PEG-Amine,CLS-PEG-NH2,胆固醇-聚乙二醇-氨基脂两亲性脂质衍生物