zoukankan      html  css  js  c++  java
  • 拖拽修改宽度

    <div className={styles.content}>
          <Row>
              <Col id="left" style={{ position: 'absolute', height: '100%',  `${this.state.width}px` }}>
                  <div/> // 这里写内容
                  <div className={styles.dropLine} onMouseDown={this.handleMouseDown} /> 左侧线
             </Col>
                <Col className={styles.right} style={{ marginLeft: `${this.state.width}px` }}>
                  <div /> // 右边内容
               </Col>
            </Row>
    </div>
     
    handleMouseDown = () => {
        document.ondragstart = (e) => {
          e.preventDefault();
        };
        document.ondragend = (e) => {
          e.preventDefault();
        };
        document.onmousemove = (ev) => {
          const ele = document.getElementById('left');
          const eve = ev || window.event;
          const left = this.getOffsetPosition(ele);
          const width = eve.clientX - left;
          if (width >= 244 && width < 800) {
            this.setState({
              width,
            });
          }
          document.onmouseup = () => {
            document.onmousemove = null;
            document.onmousedown = null;
          };
        };
      }

      getOffsetPosition = (ele, x) => {
        const left = x || 0;
        if (ele.offsetParent != null) {
          return this.getOffsetPosition(ele.offsetParent, ele.offsetLeft + left);
        }
        return left;
      }
     
    .dropLine {
        background: #e0e0e0;
         1px;
        min-height: calc(~"100vh - 70px");
        height: 100%;
        top: 0px;
        z-Index: 0;
        right: 0px;
        cursor: w-resize;
        position: absolute;
    }
    .dropLine::after {
        position: absolute;
        left: -6px;
        top: 0px;
        height: 100%;
         14px;
        content: '';
        display: block;
    }
  • 相关阅读:
    软件测试基础
    Python
    Python
    C# 打开帮助文档,打开电脑中其他应用或者文件
    C# 设置窗口大小为不可调、取消最大化、最小化窗口按键
    C# 控件置于最顶层、最底层、隐藏、显示
    C# 在窗口绘制图形(打点、画圆、画线)
    C# 不同窗口传递参数
    C# 禁止在textBox输入框输入非法字符
    C# 设定弹出窗体位置
  • 原文地址:https://www.cnblogs.com/hamili/p/12018047.html
Copyright © 2011-2022 走看看