利用vue实现div宽度拖拽效果的思路和代码是什么
Admin 2022-09-09 群英技术资讯 496 次浏览
主要思路
<template>
<div class="container" id="content_box">
<div class="tab">左侧Tab</div>
<div class="menu" ref="menu">
左侧菜单
<div class="menu-resize" ref="menuResize"></div>
</div>
<div class="content">
中心区域
<div class="opera" ref="opera">
<div class="opera-resize" ref="operaResize"></div>
操作区域
</div>
</div>
</div>
</template>
<script>
export default {
name: "dropWidth",
mounted() {
this.$nextTick(() => {
this.dropSize();
})
},
methods: {
dropSize() {
let that = this,
menuWidth = 200,
operaHeight = 200;
this.$refs.menuResize.onmousedown = function () {
document.onmousemove = function (e) {
let clientX = e.clientX;
// 最大宽度
if(clientX>=330){
clientX = 330;
}
// 最小宽度
if(clientX<=230){
clientX = 230;
}
// TODO 这里减的是最左侧tab的宽度
menuWidth = clientX - 30;
that.$refs.menu.style.width = clientX - 30 +"px";
}
document.onmouseup = function () {
console.log('当前宽度', menuWidth);
document.onmousemove = null;
document.onmouseup = null;
that.releaseCapture && that.releaseCapture()
}
}
this.$refs.operaResize.onmousedown = function () {
document.onmousemove = function (e) {
let clientY = e.clientY;
console.log(clientY)
// 最大宽度
if(clientY<=100){
clientY = 100;
}
// 最小宽度
if(clientY>=300){
clientY = 300;
}
operaHeight = clientY;
// TODO 这里需要取反向
that.$refs.opera.style.height = 400 - clientY +"px";
}
document.onmouseup = function () {
console.log('当前宽度', operaHeight);
document.onmousemove = null;
document.onmouseup = null;
that.releaseCapture && that.releaseCapture()
}
}
}
}
}
</script>
<style scoped>
.container {
width: 1000px;
height: 400px;
border: 2px solid #dddddd;
display: flex;
justify-content: center;
}
.tab {
width: 30px;
height: 100%;
background-color: #EC8C32;
flex-shrink: 0;
flex-grow: 0;
}
.menu {
width: 200px;
background-color: #AAB6E0;
flex-shrink: 0;
flex-grow: 0;
position: relative;
}
.content {
width: 100%;
position: relative;
}
.opera {
width: 100%;
height: 200px;
position: absolute;
bottom: 0;
background-color: #F2BE25;
}
.menu-resize {
width: 5px;
height: 100%;
position: absolute;
top: 0;
right: 0;
cursor: col-resize;
}
.opera-resize {
width: 100%;
height: 5px;
position: absolute;
top: 0;
left: 0;
cursor: row-resize;
}
</style>
实现效果
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章介绍了Node.js实现链式回调的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
这篇文章主要介绍了Webpack的Loader和Plugin的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
怎样用vue实现一个无缝的轮播效果?对于轮播效果的应用场景有很多,我们经常能在网站的头部看到,轮播功能也是比较实用的,但是一些新手在刚接触轮播时,实现的轮播效果有缝隙,效果并不好看,对此下面小编就给大家分享实现无缝轮播效果的代码。
目录正文npm2yarnpnpm总结正文大家最近是不是经常听到 pnpm,我也一样。今天研究了一下它的机制,确实厉害,对 yarn 和 npm 可以说是降维打击。那具体好在哪里呢? 我们一起来看一下。我们按照包管理工具的发展历史,从 npm2 开始讲起:npm2用 node 版本管理工具把 node 版本降到 4,那
这篇文章主要为大家详细介绍了vue实现div高度可拖拽,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008