<
>

vue实现div高度可拖拽

2022-04-15 09:50:08 来源:易采站长站 作者:

本文实例为大家分享了vue实现div高度可拖拽的具体代码,供大家参考,具体内容如下

这里有一个现成的demo,可以实现页面div的拖拽功能,但是和我想要的效果不是很一样,所以说后边有根据我的实际需求又重新修改了 //得到点击时该地图容器的宽高: var targetDivHeight = targetDiv.offsetHeight; var startX = e.clientX; var startY = e.clientY; var _this = this; document.onmousemove = function (e) { e.preventDefault(); //得到鼠标拖动的宽高距离:取绝对值 var distY = Math.abs(e.clientY - startY); //往上方拖动: if (e.clientY < startY) { targetDiv.style.height = targetDivHeight - distY + 'px'; } //往下方拖动: if (e.clientX < startX && e.clientY > startY) { targetDiv.style.height = (targetDivHeight + distY) + 'px'; } if (parseInt(targetDiv.style.height) >= 320) { targetDiv.style.height = 320 + 'px'; } if (parseInt(targetDiv.style.height) <= 160) { targetDiv.style.height = 160 + 'px'; } } document.onmouseup = function () { document.onmousemove = null; } },

然后给他们设置一下css样式,其实这个地方就随意了,根据自己喜好来。

  #tz {    width: 100%;    height: 5px;    cursor: s-resize;    z-index: 200001;  }    #move_tz {    width: 100%;    height: 5px;    cursor: s-resize;    z-index: 100;    background-image: url("");    background-position: 0px 0px;  }

最后效果:

vue实现div高度可拖拽

效果不是特别的好,还有很多地方是值得优化以下的,暂时不写了。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

暂时禁止评论

微信扫一扫

易采站长站微信账号