当前位置:网站首页>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![]()
边栏推荐
猜你喜欢
随机推荐
雷克萨斯lm的安全性如何?
HCIP(17)
秒懂网络拓扑中的下一跳地址
Shunted Self-Attention via Multi-Scale Token Aggregation
AcWing 2983. 玩具
WAF WebShell Trojan free to kill
No-code development platform form styling steps introductory course
脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3
数据库审计 - 网络安全的重要组成部分
IDO预售代币合约系统开发技术说明及源码分析
Pytest配置项-pytest.ini
一个很少见但很有用的SQL功能
airflow db init 报错
HCIP(16)
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?
CIO修炼手册:成功晋升CIO的七个秘诀
基于STM32设计的老人防摔倒报警设备(OneNet)
停止使用 Storyboards 和 Interface Builder
2022中国眼博会,山东眼健康展,视力矫正仪器展,护眼产品展
qt静态编译出现Project ERROR: Library ‘odbc‘ is not defined








