当前位置:网站首页>解决微信小程序rich-text富文本标签内部图片宽高自适应的方法
解决微信小程序rich-text富文本标签内部图片宽高自适应的方法
2022-06-24 09:40:00 【徊忆羽菲】
解决微信小程序rich-text富文本标签内部图片宽高自适应的方法
rich-text富文本标签
rich-text是微信小程序的富文本标签,在使用rich-text的时候,需要rich-text内部图片宽高自适应,这个时候该怎么做呢?先来看下案例:
<view class="contentLine">
<rich-text nodes="{
{content}}"></rich-text>
</view>
方案
上面是一个rich-text富文本在wxml中的使用示例,这个时候我们需要给它设置content参数,content就是一个富文本内容,在js中可以这样设置:
onLoad: function (options) {
var mycontent = "<img src='https://www.tpyyes.com/cat.jpg'/>";
mycontent = mycontent.replace(/\<img/gi, '<img style="width:100%;height:auto"');
this.setData({
content: mycontent
});
}
说明
上面是rich-text设置富文本内容的方法,如果内容没有经过replace替换的话,图片会超出屏幕范围,想要实现rich-text内部图片自适应,就需要把标签的style属性中加入“width:100%;height:auto” (宽度100%,高度自适应,也就是会保持图片的原始比例)。
边栏推荐
- Operator details
- 411 stack and queue (20. valid parentheses, 1047. delete all adjacent duplicates in the string, 150. inverse Polish expression evaluation, 239. sliding window maximum, 347. the first k high-frequency
- 被困英西中学的师生安全和食物有保障
- JS proxy mode
- SQL statistics of users logged in for N consecutive days
- Symbol.iterator 迭代器
- Can the long-term financial products you buy be shortened?
- NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
- Thinkphp5 multi language switching project practice
- El table Click to add row style
猜你喜欢

Groovy obtains Jenkins credentials through withcredentials

Go language development environment setup +goland configuration under the latest Windows

大中型企业如何构建自己的监控体系

JS singleton mode

How does home office manage the data center network infrastructure?

居家办公如何管理数据中心网络基础设施?

Troubleshooting steps for Oracle pool connection request timeout

时尚的弹出模态登录注册窗口

Phpstrom code formatting settings

Floating point notation (summarized from cs61c and CMU CSAPP)
随机推荐
SVG+js拖拽滑块圆形进度条
微信小程序學習之 實現列錶渲染和條件渲染.
二叉树第一部分
Geogebra instance clock
canvas 绘制图片
为什么 JSX 语法这么香?
Indexeddb local storage, homepage optimization
Endgame P.O.O
Desktop software development framework reward
canvas无限扫描js特效代码
p5.js千纸鹤动画背景js特效
[input method] so far, there are so many Chinese character input methods!
Detailed explanation of PHP singleton mode
MYSQL数据高级
indexedDB本地存储,首页优化
SQL statistics of users logged in for N consecutive days
JS proxy mode
观察者模式
二叉樹第一部分
Why is JSX syntax so popular?