当前位置:网站首页>小程序 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
}
边栏推荐
- dedecms模板文件讲解以及首页标签替换
- 微信小程序學習之 實現列錶渲染和條件渲染.
- About thinkphp5, use the model save() to update the data prompt method not exist:think\db\query- & gt; Error reporting solution
- Cookie encryption 4 RPC method determines cookie encryption
- Graffiti smart brings a variety of heavy smart lighting solutions to the 2022 American International Lighting Exhibition
- Wechat applet learning to achieve list rendering and conditional rendering
- PHP uses recursive and non recursive methods to create multi-level folders
- 413 binary tree Foundation
- Which of the top ten securities companies has the lowest Commission and is the safest and most reliable? Do you know anything
- 居家办公如何管理数据中心网络基础设施?
猜你喜欢

微信小程序学习之 实现列表渲染和条件渲染.

SSH Remote Password free login

Record the range of data that MySQL update will lock

Wechat applet learning to achieve list rendering and conditional rendering

如何规范化数据中心基础设施管理流程

How does home office manage the data center network infrastructure?

队列Queue

2021-08-17

二叉树第一部分

canvas无限扫描js特效代码
随机推荐
port 22: Connection refused
NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
414-二叉树的递归遍历
413 binary tree Foundation
100 GIS practical application cases (XIV) -arcgis attribute connection and using Excel
LeetCode: 137. Number II that appears only once
[db2] sql0805n solution and thinking
LeetCode: 377. Combined sum IV
Amendment to VPP implementation policy routing
买的长期理财产品,可以转短吗?
读取csv(tsv)文件出错
Basic operations on binary tree
How to standardize data center infrastructure management process
请问有国内靠谱低手续费的期货开户渠道吗?网上开户安全吗?
Detailed explanation of ThinkPHP 5.0 Model Association
Indexeddb local storage, homepage optimization
新手怎么选择投资理财产品的等级?
保健品一物一码防窜货营销软件开发
Groovy obtains Jenkins credentials through withcredentials
Why is JSX syntax so popular?