dragHeight.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * v-dialogDragWidth 可拖动弹窗高度(右下角)
  3. * Copyright (c) 2019 ruoyi
  4. */
  5. export default {
  6. bind(el) {
  7. const dragDom = el.querySelector('.el-dialog');
  8. const lineEl = document.createElement('div');
  9. lineEl.style = 'width: 6px; background: inherit; height: 10px; position: absolute; right: 0; bottom: 0; margin: auto; z-index: 1; cursor: nwse-resize;';
  10. lineEl.addEventListener('mousedown',
  11. function(e) {
  12. // 鼠标按下,计算当前元素距离可视区的距离
  13. const disX = e.clientX - el.offsetLeft;
  14. const disY = e.clientY - el.offsetTop;
  15. // 当前宽度 高度
  16. const curWidth = dragDom.offsetWidth;
  17. const curHeight = dragDom.offsetHeight;
  18. document.onmousemove = function(e) {
  19. e.preventDefault(); // 移动时禁用默认事件
  20. // 通过事件委托,计算移动的距离
  21. const xl = e.clientX - disX;
  22. const yl = e.clientY - disY
  23. dragDom.style.width = `${curWidth + xl}px`;
  24. dragDom.style.height = `${curHeight + yl}px`;
  25. };
  26. document.onmouseup = function(e) {
  27. document.onmousemove = null;
  28. document.onmouseup = null;
  29. };
  30. }, false);
  31. dragDom.appendChild(lineEl);
  32. }
  33. }