美文网首页
拖拽改变div大小实现

拖拽改变div大小实现

作者: 用技术改变世界 | 来源:发表于2020-11-10 09:42 被阅读0次

    在块底部增加div

            <section ref="topTableWrap" class="top-table-wrapper">

                <new-stock-info-table ref="newStockInfoTable" :filter-field="filterField" component="confirm-offer" @onRowClick="onRowClick($event)"></new-stock-info-table>

                <div ref="dragLine" class="drag-line"></div>

            </section>

    样式:

                .drag-line {

                    position: absolute;

                    width: 100%;

                    border-bottom: 2px solid #c8c7c7;

                    &:hover {

                        cursor: n-resize;

                        border-bottom: 3px solid #bfbfbf;

                    }

                }

    在data里定义变量:

        isMouseDown = false;

        mouseDownY = 0;

    生命周期mounted里:”

        mounted() {

            (<any>this.$refs.dragLine).onmousedown = e => {

                this.mouseDownY = e.pageY;

                this.isMouseDown = true;

            };

            document.onmouseup = () => {

                this.isMouseDown = false;

            };

            document.onclick = () => {

                this.isMouseDown = false;

            };

            document.onmousemove = e => {

                e.preventDefault();

                let moveY = this.mouseDownY - e.pageY;

                this.mouseDownY = e.pageY;

                if (this.isMouseDown) {

                    (<any>this.$refs.topTableWrap).style.height = (<any>this.$refs.topTableWrap).offsetHeight - moveY + 'px';

                }

            };

        }

    相关文章

      网友评论

          本文标题:拖拽改变div大小实现

          本文链接:https://www.haomeiwen.com/subject/bcvdbktx.html