xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
提交 | 用户 | 时间
722af2 1 /**
X 2 * v-dialogDragWidth 可拖动弹窗宽度(右侧边)
3 * Copyright (c) 2019 dl
4 */
5
6 export default {
7     bind(el) {
8         const dragDom = el.querySelector('.el-dialog');
9         const lineEl = document.createElement('div');
10         lineEl.style = 'width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;';
11         lineEl.addEventListener('mousedown',
12             function (e) {
13                 // 鼠标按下,计算当前元素距离可视区的距离
14                 const disX = e.clientX - el.offsetLeft;
15                 // 当前宽度
16                 const curWidth = dragDom.offsetWidth;
17                 document.onmousemove = function (e) {
18                     e.preventDefault(); // 移动时禁用默认事件
19                     // 通过事件委托,计算移动的距离
20                     const l = e.clientX - disX;
21                     dragDom.style.width = `${curWidth + l}px`;
22                 };
23                 document.onmouseup = function (e) {
24                     document.onmousemove = null;
25                     document.onmouseup = null;
26                 };
27             }, false);
28         dragDom.appendChild(lineEl);
29     }
30 }