当前位置:网站首页>Image preview embedding location of blog maintenance record
Image preview embedding location of blog maintenance record
2022-07-26 19:33:00 【Xiao Wu can't type the code, can he】
The embedding position of image preview in blog maintenance records
Welcome to my personal blog to check the original
Welcome to follow my personal public number : Marigold

Catalog
【 Problem description 】
In the article reading interface , Click on the picture in the article , Preview the picture , The expected results are as follows :
The actual effect of the final launch is as follows :

You can see , Picture at parent div Horizontal and vertical center display .
【 Problem solving 】
The first thought is to modify CSS Style solves this problem , But the level is limited , I only thought of a solution to the symptoms rather than the root cause ( Strictly speaking, it does not cure the symptoms ), I hope the boss can give me some advice .v-note-img-wrapper The original style attributes of are as follows :
.v-note-img-wrapper {
position: fixed;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: rgba(0,0,0,0.7);
z-index: 1600;
-webkit-transition: all 0.1s linear 0s;
transition: all 0.1s linear 0s;
}
The problem I have been unable to solve is this v-note-img-wrapper Of div, Always follow the parent div Scroll .
The second way is through JavaScript operation DOM Elements , take v-note-img-wrapper This div Put it in body That's fine . That way , The operation logic after clicking the image is clear .

The specific code is as follows :
...
<mavon-editor
v-model="work.content"
:subfield="false"
:toolbarsFlag="false"
defaultOpen="preview"
ref="work"
:editable="false"
codeStyle="darcula"
:imageClick="imageClick"
/>
...
...
imageClick(e) {
// Get the clicked image url
let url = e.src;
// establish img label
let imgTag = document.createElement("img");
imgTag.src = url;
// Image screen adaptation
if (e.width * 1.5 < window.innerWidth) {
if (e.height * 1.5 < window.innerHeight) {
imgTag.style.width =
e.width * 1.5 < window.innerWidth
? e.width * 1.5 + "px"
: window.innerWidth * 0.95 + "px";
} else {
imgTag.style.height = window.innerHeight * 0.95 + "px";
}
} else {
imgTag.style.height = window.innerHeight * 0.95 + "px";
}
// establish div label
let wrap = document.createElement("div");
// Set tag properties
wrap.classList.add("v-note-img-wrapper");
// Set the mouse style to zoom out
wrap.style.cursor = "zoom-out";
// take img Label to join div In the child node
wrap.appendChild(imgTag);
// Set click listening function to close preview
wrap.addEventListener("click", function () {
wrap.remove();
});
// obtain body The first child node of
let first = document.body.firstChild;
// take div Insert
document.body.insertBefore(wrap, first);
},
...
Final effect :
【 summary 】
- This little problem took me half a day , In fact, it won't take so long , In the final analysis, yes CSS、JavaScript Not familiar with .
- Yes Vue Transfer functions between parent and child components , In particular, functions that pass parameters as events are unfamiliar .
- This implementation has fewer functions , You can also consider adding thumbnails , The previous one , The function of the latter one .
边栏推荐
- J1:Redis为什么这么快+基本结构
- [server data recovery] data recovery case of server storage shared folder loss
- Don't casually pass the request to the asynchronous thread. You can't handle it. You have to use the startasync method
- 如果密钥忘记,多个设备分别不同的密钥,云端是如何同步
- 安全测试与功能测试、渗透测试你知道有什么区别吗?
- Write a starter
- [C language implementation] - dynamic / file / static address book
- 最后一篇博客
- NLP 学习之路
- This article explains in detail the five benefits that MES system brings to enterprises, with application scenarios
猜你喜欢

关于接口测试你想知道的都在这儿了

什么是服务器集群?海外服务器集群的优势?

C#上位机开发—— 修改窗口图标和exe文件图标

Synchronized theory

Mathematical basis of deep learning

Verification palindrome string II of leetcode simple question

2022搭建企业级数据治理体系

The inventory of chips in the United States is high, and the shipment of chips in China has increased rapidly and the import of 28.3 billion chips has been greatly reduced. TSMC has a showdown

C # get local time / system time
![[server data recovery] data recovery case of server storage shared folder loss](/img/bf/3f86a4e8abd4e045b022fd7574636f.png)
[server data recovery] data recovery case of server storage shared folder loss
随机推荐
The role of @requestmapping in the project and how to use it
To add a composite primary key
查看容器的几种方式
节省50%成本 京东云发布新一代混合CDN产品
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
The difference between advanced anti DDoS server and advanced anti DDoS IP
Is it safe for CSC qiniu members to open preferential accounts? I don't know if it's the lowest Commission
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_ scale_ factor‘
conda转移项目虚拟环境必备技能+pip速度下载太慢解决办法
Four methods of closing forms in C #
Synchronized理论
J2 Redis之 AOF&RDB
还在用Xshell?你out了,推荐一个更现代的终端连接工具
How to solve the problem that win11 has been switched on after upgrading
Zbxtable 2.0 heavy release! 6 major optimization functions!
Leetcode notes: biweekly contest 83
Cannot find current proxy: Set ‘exposeProxy‘ property on Advised to ‘true‘ to make it available
Vs2019 export import configuration
Network protocol: tcp/ip protocol
自动化测试的使用场景