当前位置:网站首页>Image click enlargement and adaptive size in the applet rich text
Image click enlargement and adaptive size in the applet rich text
2022-06-24 10:24:00 【Wandering in memory of Yu Fei】
Applet rich-text Click to enlarge and self-adaptive size of Chinese pictures
Click to enlarge the picture
// js
data:{
imgarr:[]
}
// Main code
let imgarr = [];
let regex = new RegExp(/<img.*?(?:>|\/>)/gi); // Match all pictures
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; // matching src picture
let arrsImg = obj.info.match(regex); // obj.info Rich text data returned in the background
for (let a = 0; a < arrsImg.length; a++) {
let srcs = arrsImg[a].match(srcReg);
imgarr.push(srcs[1])
}
this.setData({
imgarr
})
// Click the zoom in preview picture function
catchImage(e){
console.log(this.data.imgarr);
wx.previewImage({
current: this.data.imgarr[0], // The http link
urls: this.data.imgarr // Pictures that need to be previewed http Link list
})
},
// html
<view class="mdl-xq">
<rich-text nodes="{
{ goodObj.info }}" space="ensp" catchtap="catchImage"></rich-text>
</view>
Adaptive size
// obj.info Rich text data returned in the background
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; // These two lines of code mainly solve the problem of white space between pictures
flex-direction: column; // These two lines of code mainly solve the problem of white space between pictures
padding:20rpx;
}
.fwb-img {
max-width: 100% !important;
width: 100% !important;
height: auto !important;
display: block
}
边栏推荐
- Network of test and development - Common Service Protocols
- Resolved: methods with the same name as their class will not be constructors in
- 【资源分享】2022年环境工程与生物技术国际会议(CoEEB 2022)
- 包装类型的缓存机制
- SQL Sever中的窗口函数row_number()rank()dense_rank()
- 消息队列的作用
- 图解杂项【防止丢失进行存档用的】
- Caching mechanism for wrapper types
- Role of message queuing
- 线程调度的常用方法
猜你喜欢
JMeter接口测试工具基础— 使用Badboy录制JMeter脚本
简单的价格表样式代码
消息队列的作用
leetCode-223: 矩形面积
1. project environment construction
Role of message queuing
p5.js千纸鹤动画背景js特效
4. classification management business development
6. package management business development
Development of anti fleeing marketing software for health products
随机推荐
Safety and food security for teachers and students of the trapped Yingxi middle school
Uniapp develops a wechat applet to display the map function, and click it to open Gaode or Tencent map.
leetCode-498: 对角线遍历
【资源分享】2022年第五届土木,建筑与环境工程国际会议(ICCAEE 2022)
np.float32()
uniapp实现禁止video拖拽快进
整理接口性能优化技巧,干掉慢代码
SQL sever基本数据类型详解
分布式系统你必须了解的点-CAP
机器学习——感知机及K近邻
引擎国产化适配&重构笔记
leetCode-面试题 01.05: 一次编辑
canvas掉落的小球重力js特效动画
The difference between static link library and dynamic link library
3. addition, deletion, modification and query of employees
Common methods of thread scheduling
SSM integration
学习使用KindEditor富文本编辑器,点击上传图片遮罩太大或白屏解决方案
Machine learning - principal component analysis (PCA)
Learning to organize using kindeditor rich text editor in PHP