vue拖动改变div宽度

TextWidthChange(e) {
        let odivParent = e.currentTarget.parentNode; //获取目标父元素
        let dx= e.clientX;//当你第一次单击的时候,存储x轴的坐标。
        let dw= odivParent.offsetWidth;//存储默认的div的宽度。
        document.onmousemove = e => {
            odivParent.style.width=dw+(e.clientX-dx)+'px';

            if(odivParent.offsetWidth <= 100){//当盒子缩小到一定范围内的时候,让他保持一个固定值,不再继续改变
              odivParent.style.width='100px';
            }

            if(odivParent.offsetWidth + odivParent.offsetLeft >= this.pdfWidth){
              odivParent.style.width = this.pdfWidth - odivParent.offsetLeft + 'px';
            }
        };
        document.onmouseup = e => {
          document.onmousemove = null;
          document.onmouseup = null;
        };
        e.stopPropagation();
        e.preventDefault();
        return false;
      },
dom.childNodes[4].onmousedown = this.TextWidthChange;

猜你喜欢

转载自blog.csdn.net/qq_38188485/article/details/105516336
今日推荐