• vue实现左侧拖拽拉伸,展开收起


    需求:1.左侧是个树形结构,有的文字过长展示不全,想通过拖拽显示全部的数据
               2.展开收起

    实现图中效果

    1. <div class="catalog-drag">
    2. <svg t="1687228434888" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1527" width="16" height="30"><path d="M446.464 146.944v727.552c0 15.872-14.336 27.648-31.744 27.648-17.92 0-31.744-12.288-31.744-27.648V146.944c0-15.872 14.336-27.648 31.744-27.648 17.408-0.512 31.744 11.776 31.744 27.648zM644.608 146.944v727.552c0 15.872-14.336 27.648-31.744 27.648-17.92 0-31.744-12.288-31.744-27.648V146.944c0-15.872 14.336-27.648 31.744-27.648 17.408-0.512 31.744 11.776 31.744 27.648zM84.48 525.312c-8.192-7.68-8.192-22.528 0-30.208L180.224 409.6l88.064-78.848c10.24-9.216 24.576 0 24.576 14.848v328.704c0 15.36-14.336 24.576-24.576 14.848l-88.064-78.848-95.744-84.992zM942.592 525.312c8.192-7.168 8.192-22.016 0-29.696l-95.744-84.992L758.784 332.8c-10.24-9.216-24.576 0-24.576 14.848v325.632c0 15.36 14.336 24.064 24.576 14.848l88.064-77.824 95.744-84.992z" fill="#707070" p-id="1528"></path> </svg>
    3. </div>
    4. //左侧侧边栏拖拽事件
    5. handleLeft() {
    6. console.log("左侧侧边栏拖拽事件");
    7. var leftBar = document.getElementsByClassName("catalog-drag")[0];
    8. var leftTree = document.getElementsByClassName("product-catalog-tree")[0];
    9. // 鼠标按下事件
    10. leftBar.onmousedown = function () {
    11. // 颜色提醒
    12. leftBar.style.backgroundColor = "#99B8FC";
    13. // 鼠标拖动事件
    14. document.onmousemove = function (eventMove) {
    15. let width = eventMove.clientX + 20;
    16. console.log("width =>", width);
    17. if (width >= 600) {
    18. width = 600; // 设置最大拉伸宽度为600
    19. } else if (width <= 200) {
    20. // 当拉伸宽度为小于或等于200,最小拉伸宽度为200
    21. width = 294;
    22. }
    23. leftBar.style.width = width + "px";
    24. };
    25. // 鼠标松开事件
    26. document.onmouseup = function () {
    27. // 颜色恢复
    28. leftBar.style.backgroundColor = "#fafcff";
    29. document.onmousemove = null;
    30. document.onmouseup = null;
    31. leftBar .releaseCapture && leftResizeBar.releaseCapture();
    32. };
    33. leftBar.setCapture && leftBar.setCapture();
    34. return false;
    35. };
    36. },
    37. .catalog-drag {
    38. position: absolute;
    39. width: 4px;
    40. top: 0;
    41. right: 0;
    42. height: 100%;
    43. cursor: col-resize;
    44. padding-top: calc(45vh - 10px);
    45. user-select: none;
    46. transition: all ease 0.3s;
    47. }
    48. .catalog-drag:hover {
    49. background-color: #99b8fc !important;
    50. }
    51. .catalog-drag svg {
    52. position: absolute;
    53. left: 1;
    54. }

    在mounted里面调用就可以了

    实现左侧展开收起

    1. <div @click="handleShowLeft">
    2. <img v-if="!isShowLeft" src="../../new_/imgs/icon-fold.svg" style="width:14px" />
    3. <img v-else src="../../new_/imgs/icon-upfold.svg" style="width: 14px" />
    4. </div>
    5. // 左侧展开收起
    6. handleShowLeft() {
    7. this.isShowLeft= !this.isShowLeft;
    8. var leftTree = document.getElementsByClassName(
    9. "product-catalog-tree"
    10. )[0];
    11. if (this.isShowLeft) {
    12. leftTree .style.width = "26px";
    13. } else {
    14. leftTree.style.width = "294px";
    15. setTimeout(() => {
    16. //展开后还能继续拖拽
    17. this.handleLeft();
    18. }, 100);
    19. }
    20. },


     

  • 相关阅读:
    React 补充
    异形双柱体阵列纳米粒:球形纳米粒/圆盘形纳米粒子/盘状纳米粒子/棒状纳米粒子
    学习常见的反爬虫手段,如验证码、限制访问频率等
    Linux网络编程(TCP状态转换关系)
    换个数据结构,一不小心节约了 591 台机器!
    Netty网络框架学习笔记-14(ChannelPipeline、ChannelHandler、 ChannelHandlerContext创建分析)
    【C++】特殊类设计
    【Try to Hack】正向shell和反向shell
    whisper large-v3 模型文件下载链接
    springboot整合SSE
  • 原文地址:https://blog.csdn.net/xiaojiaoaozhangyi/article/details/139316752