当前位置:网站首页>Antdesign a-modal user-defined instruction realizes dragging and zooming in and out
Antdesign a-modal user-defined instruction realizes dragging and zooming in and out
2022-07-27 09:10:00 【The gentle wind is attributed to you with a smile】
import Vue from 'vue'
// v-dialogDrag: Pop up drag
Vue.directive('dragModal', {
bind(el, binding, vnode, oldVnode) {
// The minimum width and height of the elastic frame can be stretched
const minWidth = 400;
const minHeight = 300;
// Get the bullet head ( You can double-click the full screen in this section )
const dialogHeaderEl = el.querySelector('.ant-modal')
// Popup
const dragDom = el.querySelector('.ant-modal-wrap')
// Head with drag cursor
dialogHeaderEl.style.cursor = 'move';
// Get the original properties ie dom Elements .currentStyle Fox, Google window.getComputedStyle(dom Elements , null);
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
dialogHeaderEl.onmousedown = (e) => {
// The mouse click , Calculate the distance between the current element and the visible area
const disX = e.clientX - dialogHeaderEl.offsetLeft;
const disY = e.clientY - dialogHeaderEl.offsetTop;
// Get the value band px Regular match replacement
let styL, styT;
// Pay attention to ie in The value obtained for the first time is the component's own 50% After moving, the assignment is px
if (sty.left.includes('%')) {
// eslint-disable-next-line no-useless-escape
styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100);
// eslint-disable-next-line no-useless-escape
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
} else {
styL = +sty.left.replace(/\px/g, '');
styT = +sty.top.replace(/\px/g, '');
}
document.onmousemove = function(e) {
// Through event delegation , Calculate the distance of movement
const l = e.clientX - disX;
const t = e.clientY - disY;
// Move the current element
dragDom.style.left = `${l + styL}px`;
dragDom.style.top = `${t + styT}px`;
// Send out the position at this time
// binding.value({x:e.pageX,y:e.pageY})
};
document.onmouseup = function(e) {
document.onmousemove = null;
document.onmouseup = null;
};
}
dragDom.onmousemove = function(e) {
// console.log(dialogHeaderEl,dragDom.querySelector('.el-dialog__body'), 123);
const moveE = e;
if (e.clientX > dragDom.offsetLeft + dragDom.clientWidth - 10 || dragDom.offsetLeft + 10 > e.clientX) {
dragDom.style.cursor = 'se-resize';
} else if (el.scrollTop + e.clientY > dragDom.offsetTop + dragDom.clientHeight - 10) {
dragDom.style.cursor = 's-resize';
} else {
dragDom.style.cursor = 'default';
dragDom.onmousedown = null;
}
dragDom.onmousedown = (e) => {
const clientX = e.clientX;
const clientY = e.clientY;
const elW = dragDom.clientWidth;
const elH = dragDom.clientHeight;
const EloffsetLeft = dragDom.offsetLeft;
const EloffsetTop = dragDom.offsetTop;
dragDom.style.userSelect = 'none';
const ELscrollTop = el.scrollTop;
// Determine whether the click position is the head
if (clientX > EloffsetLeft && clientX < EloffsetLeft + elW && clientY > EloffsetTop && clientY < EloffsetTop + 100) {
// If it's the head here, don't do anything , The above is bound dialogHeaderEl.onmousedown = moveDown;
} else {
document.onmousemove = function(e) {
e.stopPropagation(); // Disable default events when moving
// Left mouse drag position
if (clientX > EloffsetLeft && clientX < EloffsetLeft + 10) {
// Drag to the left
if (clientX > e.clientX) {
dragDom.style.width = elW + (clientX - e.clientX) * 2 + 'px';
}
// Drag to the right
if (clientX < e.clientX) {
// eslint-disable-next-line no-empty
if (dragDom.clientWidth < minWidth) {
} else {
dragDom.style.width = elW - (e.clientX - clientX) * 2 + 'px';
}
}
}
// Right mouse drag position
if (clientX > EloffsetLeft + elW - 10 && clientX < EloffsetLeft + elW) {
// Drag to the left
if (clientX > e.clientX) {
// eslint-disable-next-line no-empty
if (dragDom.clientWidth < minWidth) {
} else {
dragDom.style.width = elW - (clientX - e.clientX) * 2 + 'px';
}
}
// Drag to the right
if (clientX < e.clientX) {
dragDom.style.width = elW + (e.clientX - clientX) * 2 + 'px';
}
}
// Bottom mouse drag position
if (ELscrollTop + clientY > EloffsetTop + elH - 20 && ELscrollTop + clientY < EloffsetTop + elH) {
// Drag up
if (clientY > e.clientY) {
// eslint-disable-next-line no-empty
if (dragDom.clientHeight < minHeight) {
} else {
dragDom.style.height = elH - (clientY - e.clientY) * 2 + 'px';
}
}
// Drag down
if (clientY < e.clientY) {
dragDom.style.height = elH + (e.clientY - clientY) * 2 + 'px';
}
}
};
// The stretch is over
document.onmouseup = function(e) {
document.onmousemove = null;
document.onmouseup = null;
};
}
}
}
}
})
Use

边栏推荐
- Replace restricts the text box to regular expressions of numbers, numbers, letters, etc
- Pyqt5 rapid development and practice 4.1 qmainwindow
- Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
- How to study happily on station B?
- Explain cache consistency and memory barrier
- CUDA programming-01: build CUDA Programming Environment
- Restful
- 基于ArkUI eTS开发的坚果食谱(NutRecipes
- TensorFlow损失函数
- How to optimize the deep learning model to improve the reasoning speed
猜你喜欢

The wechat installation package has soared from 0.5m to 260m. Why are our programs getting bigger and bigger?

Aruba学习笔记10-安全认证-Portal认证(web页面配置)

PyTorch自定义CUDA算子教程与运行时间分析

How to optimize the deep learning model to improve the reasoning speed
![Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1](/img/1c/c1c1b15e502ee901a396840c01e84d.png)
Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1

js call和apply

pollFirst(),pollLast(),peekFirst(),peekLast()

一些实用、常用、效率越来越高的 Kubernetes 别名

CUDA programming-01: build CUDA Programming Environment

Activation functions commonly used in deep learning
随机推荐
Full Permutation recursive thought sorting
vscod
巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
TensorFlow损失函数
Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry
[daily algorithm day 96] Tencent interview question: merge two ordered arrays
The wechat installation package has soared from 0.5m to 260m. Why are our programs getting bigger and bigger?
Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
Nut joke based on arkui ETS
如何注册码云账号
基于restful页面数据交互
苹果降价600元,对本就溃败的国产旗舰手机几乎是毁灭性打击
PVT's spatial reduction attention (SRA)
ArkUI中的显式动画
js call和apply
【Flutter -- GetX】准备篇
pollFirst(),pollLast(),peekFirst(),peekLast()
SQL exercise set
"Weilai Cup" 2022 Niuke summer multi school training camp 1
async/await的执行顺序以及宏任务和微任务