dragWidth.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <<<<<<< HEAD
  2. /**
  3. * v-dialogDragWidth 可拖动弹窗宽度(右侧边)
  4. * Copyright (c) 2019 ruoyi
  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. =======
  31. /**
  32. * v-dialogDragWidth 可拖动弹窗宽度(右侧边)
  33. * Copyright (c) 2019 ruoyi
  34. */
  35. export default {
  36. bind(el) {
  37. const dragDom = el.querySelector('.el-dialog');
  38. const lineEl = document.createElement('div');
  39. lineEl.style = 'width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;';
  40. lineEl.addEventListener('mousedown',
  41. function (e) {
  42. // 鼠标按下,计算当前元素距离可视区的距离
  43. const disX = e.clientX - el.offsetLeft;
  44. // 当前宽度
  45. const curWidth = dragDom.offsetWidth;
  46. document.onmousemove = function (e) {
  47. e.preventDefault(); // 移动时禁用默认事件
  48. // 通过事件委托,计算移动的距离
  49. const l = e.clientX - disX;
  50. dragDom.style.width = `${curWidth + l}px`;
  51. };
  52. document.onmouseup = function (e) {
  53. document.onmousemove = null;
  54. document.onmouseup = null;
  55. };
  56. }, false);
  57. dragDom.appendChild(lineEl);
  58. }
  59. >>>>>>> ec6eeb00ce64eb587a455406167d302dc3e59216
  60. }