话不多说,直接排版走起:
<div class="outer" ref="outer"><div class="left" @mousedown="chatDragging"></div><div class="bottom" @mousedown="chatRight"></div><div class="smart_dialog" ref="dialog"></div></div>
样式:
.outer{position: absolute;width: 400px;height: 250px;right: 35%;top: 9%;background: #fff;}.left {width: 3px;height: 100%;background: red;position: absolute;left: 0;}.bottom {width: 100%;height: 3px;background: red;position: absolute;bottom: 0;}.left:hover,.bottom:hover {cursor: row-resize;}
代码逻辑:
// 向左边拉动chatDragging (e) {let dragger = this.$refs.outerlet leftWidth = dragger.offsetWidthe.preventDefault()let startX = e.clientXdocument.onmousemove = function (e) {e.preventDefault()let endX = e.clientXlet changeWidth = endX - startXif (changeWidth < dragger.offsetWidth * 0.7) {dragger.style.width = leftWidth - changeWidth + 'px'}}document.onmouseup = function(evt) {document.onmousemove = nulldocument.onmouseup = nulldragger.releaseCapture && dragger.releaseCapture()}dragger.setCapture && dragger.setCapture()return false},// 向下边拉动chatRight (e) {let dragger = this.$refs.outerlet topHeight = dragger.offsetHeighte.preventDefault()let startY = e.clientYdocument.onmousemove = function (e) {e.preventDefault()let endY = e.clientYlet changeHeight = endY - startYconsole.log(dragger.offsetHeight)if (changeHeight < dragger.offsetHeight * 0.7) {dragger.style.height = topHeight + changeHeight + 'px'if (dragger.offsetHeight < 200) {dragger.style.height = 200 + 'px'}}}document.onmouseup = function(evt) {document.onmousemove = nulldocument.onmouseup = nulldragger.releaseCapture && dragger.releaseCapture()}dragger.setCapture && dragger.setCapture()return false},
最后的样式图:
