当前位置:网站首页>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 .
边栏推荐
- PADS画2.54mm排针
- JVM内存模型之Volatile关键字
- C语言-入门-语法-字符串(十一)
- Onion group joined hands with oceanbase to realize distributed upgrading, and global data has achieved cross cloud integration for the first time
- Distributed transaction Seata
- TB 117-2013 US Federal mandatory regulations
- 高防服务器和高防IP的区别
- Verification palindrome string II of leetcode simple question
- Reentrantlock learning --- basic method
- NLP 学习之路
猜你喜欢

一些时序建模策略(一)

数据湖--概念、特征、架构与案例概述

This article explains in detail the five benefits that MES system brings to enterprises, with application scenarios

Introduce the difference between @getmapping and @postmapping in detail

【C语言实现】----动态/文件/静态通讯录

Write a starter
![[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

C#创建及读取DAT文件案例

The difference between advanced anti DDoS server and advanced anti DDoS IP

Synchronized theory
随机推荐
C # get local time / system time
Difficult performance problems solved in those years -- ext4 defragmentation
C语言-入门-语法-字符串(十一)
C # upper computer development - modify the window icon and exe file Icon
Without Lin benjian, there would be no TSMC today!
彻底关闭win10自动更新
第九章 实用建模技术
Support proxy direct connection to Oracle database, jumpserver fortress v2.24.0 release
After the exam on June 25, see how the new exam outline reviews PMP
2022搭建企业级数据治理体系
节省50%成本 京东云发布新一代混合CDN产品
NLP learning path
用低代码搭建千人食品制造企业高效管理系统案例分析
查看容器的几种方式
微信小程序插件--wxml-to-canvas(生成图片)
利用MySQL主从复制延迟拯救误删数据
【C语言实现】----动态/文件/静态通讯录
TypeScript阶段学习
Save gas chitoken usage
[刷题] 二分答案求解