当前位置:网站首页>小程序 rich-text中图片点击放大与自适应大小问题
小程序 rich-text中图片点击放大与自适应大小问题
2022-06-24 09:40:00 【徊忆羽菲】
图片点击放大
// js
data:{
imgarr:[]
}
// 主要代码
let imgarr = [];
let regex = new RegExp(/<img.*?(?:>|\/>)/gi); // 匹配所有图片
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配src图片
let arrsImg = obj.info.match(regex); // obj.info 后台返回的富文本数据
for (let a = 0; a < arrsImg.length; a++) {
let srcs = arrsImg[a].match(srcReg);
imgarr.push(srcs[1])
}
this.setData({
imgarr
})
// 点击放大预览图片函数
catchImage(e){
console.log(this.data.imgarr);
wx.previewImage({
current: this.data.imgarr[0], // 当前显示图片的http链接
urls: this.data.imgarr // 需要预览的图片http链接列表
})
},
// html
<view class="mdl-xq">
<rich-text nodes="{
{ goodObj.info }}" space="ensp" catchtap="catchImage"></rich-text>
</view>
自适应大小
// obj.info 后台返回的富文本数据
obj.info = obj.info.replace(/<img/gi, '<img class="fwb-img"')
.replace(/<section/g, '<div')
.replace(/\/section>/g, '\div>');
// html:
<view class="mdl-xq">
<rich-text nodes="{
{ goodObj.info }}" space="ensp"></rich-text>
</view>
// css:
.mdl-xq {
display: flex; // 这两行代码主要解决图片之间有白色间隔的问题
flex-direction: column; // 这两行代码主要解决图片之间有白色间隔的问题
padding:20rpx;
}
.fwb-img {
max-width: 100% !important;
width: 100% !important;
height: auto !important;
display: block
}
边栏推荐
猜你喜欢

机器学习——主成分分析(PCA)

利用pandas读取SQL Sever数据表

Phpstrom code formatting settings

Nvisual digital infrastructure operation management software platform

Binary tree part I

Internet of things? Come and see Arduino on the cloud

Troubleshooting steps for Oracle pool connection request timeout

How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!

小程序学习之获取用户信息(getUserProfile and getUserInfo)

美国电子烟巨头 Juul 遭遇灭顶之灾,所有产品强制下架
随机推荐
Jcim | AI based protein structure prediction in drug discovery: impacts and challenges
[custom endpoint and implementation principle]
2021-08-17
Distributed | how to make "secret calls" with dble
JS singleton mode
CVPR 2022 Oral | 英伟达提出自适应token的高效视觉Transformer网络A-ViT,不重要的token可以提前停止计算
生产者/消费者模型
PHP uses recursive and non recursive methods to create multi-level folders
CICFlowMeter源码分析以及为满足需求而进行的修改
JS proxy mode
SQL-统计连续N天登陆的用户
读取csv(tsv)文件出错
port 22: Connection refused
编程题(持续更新)
Is there a reliable and low commission futures account opening channel in China? Is it safe to open an account online?
How do novices choose the grade of investment and financial products?
Engine localization adaptation & Reconstruction notes
Nvisual digital infrastructure operation management software platform
2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
请问有国内靠谱低手续费的期货开户渠道吗?网上开户安全吗?