dragHeight.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. export default {
  11. bind(el) {
  12. const dragDom = el.querySelector('.el-dialog');
  13. const lineEl = document.createElement('div');
  14. lineEl.style =
  15. 'width: 6px; background: inherit; height: 10px; position: absolute; right: 0; bottom: 0; margin: auto; z-index: 1; cursor: nwse-resize;';
  16. lineEl.addEventListener(
  17. 'mousedown',
  18. function (e) {
  19. // 鼠标按下,计算当前元素距离可视区的距离
  20. const disX = e.clientX - el.offsetLeft;
  21. const disY = e.clientY - el.offsetTop;
  22. // 当前宽度 高度
  23. const curWidth = dragDom.offsetWidth;
  24. const curHeight = dragDom.offsetHeight;
  25. document.onmousemove = function (e) {
  26. e.preventDefault(); // 移动时禁用默认事件
  27. // 通过事件委托,计算移动的距离
  28. const xl = e.clientX - disX;
  29. const yl = e.clientY - disY;
  30. dragDom.style.width = `${curWidth + xl}px`;
  31. dragDom.style.height = `${curHeight + yl}px`;
  32. };
  33. document.onmouseup = function (e) {
  34. document.onmousemove = null;
  35. document.onmouseup = null;
  36. };
  37. },
  38. { passive: true },
  39. );
  40. dragDom.appendChild(lineEl);
  41. },
  42. };