原文链接:https://www.cnblogs.com/layaling/p/11009570.html

原文是左中右三种情况的拖动。由于项目需要,我删除掉了右边的,直接左右区域拖动调整div宽度

1、拖动,调整左右两侧宽度

<template>
<div class="wid100 hig100">
<ul class="box" ref="box">
<li class="left" ref="left">西瓜</li>
<li class="resize" ref="resize"></li>
<li class="mid" ref="mid">备注2</li>
</ul>
<ul class="box" ref="box">
<li class="left" ref="left">西瓜</li>
<li class="resize" ref="resize"></li>
<li class="mid" ref="mid">备注2</li>
</ul>
</div>
</template> <script>
export default {
name: 'Dashboard',
mounted () {
this.dragControllerDiv();
},
methods: {
dragControllerDiv: function () {
var resize = document.getElementsByClassName('resize');
var left = document.getElementsByClassName('left');
var mid = document.getElementsByClassName('mid');
var box = document.getElementsByClassName('box');
for (let i = 0; i < resize.length; i++) {
// 鼠标按下事件
resize[i].onmousedown = function (e) {
var startX = e.clientX;
resize[i].left = resize[i].offsetLeft;
// 鼠标拖动事件
document.onmousemove = function (e) {
var endX = e.clientX;
var moveLen = resize[i].left + (endX - startX); // (endx-startx)=移动的距离。resize[i].left+移动的距离=左边区域最后的宽度
var maxT = box[i].clientWidth - resize[i].offsetWidth; // 容器宽度 - 左边区域的宽度 = 右边区域的宽度 if (moveLen < 150) moveLen = 150; // 左边区域的最小宽度为150px
if (moveLen > maxT - 150) moveLen = maxT - 150; //右边区域最小宽度为150px resize[i].style.left = moveLen; // 设置左侧区域的宽度 for (let j = 0; j < left.length; j++) {
left[j].style.width = moveLen + 'px';
mid[j].style.width = (box[i].clientWidth - moveLen - 10) + 'px';
}
}
// 鼠标松开事件
document.onmouseup = function (evt) {
document.onmousemove = null;
document.onmouseup = null;
resize[i].releaseCapture && resize[i].releaseCapture(); //当你不在需要继续获得鼠标消息就要应该调用ReleaseCapture()释放掉
}
resize[i].setCapture && resize[i].setCapture(); //该函数在属于当前线程的指定窗口里设置鼠标捕获
return false;
}
} }
}
}
</script> <style lang="scss" scoped>
ul,li{
list-style: none;
display: block;
margin:0;
padding:0;
}
.box{
width:100%;
height: 48%;
margin: 1% 0px;
overflow:hidden;
}
.left{
width:calc(30% - 10px);
height:100%;
background:#c9c9c9;
float:left;
}
.resize{
width:5px;
height:100%;
cursor: w-resize;
float:left;
}
.mid{
float:left;
width:70%;
height:100%;
background:#f3f3f3;
}
</style>

  

vue 拖动调整左右两侧div的宽度的更多相关文章

  1. 拖动调整div布局大小

    一.需求 实现类似windows软件的那种,拖动调整两个div的大小 二.结果示例: 三.示例代码: https://github.com/CinYung/jQuery.divResizer.git

  2. jQuery拖动调整表格列宽度-resizableColumns

    实现鼠标可拖动调整表格列宽度 如图: 一.引入文件: <script src="/js/jquery-1.8.0.min.js" type="text/javasc ...

  3. 关于Div的宽度与高度的100%设定

    http://www.cnblogs.com/clare-zhang/archive/2011/08/26/2154220.html 正像你所知道的那样,设置DIV大小的有两个属性width和heig ...

  4. 如何设置div的宽度为100%-xx px?

    如何设置div的宽度为100%-xx px? 参见如下帖子:http://stackoverflow.com/questions/15183069/div-width-100-10px-relativ ...

  5. Div的宽度与高度的100%设定

    div的100%是从其上一级div的宽高继承来的,所以必须设置其上一级div的宽度或高度,否则无效. 举例说明:父div(deman)宽300高200,子div(cc)如果在这个条件下设置divcc的 ...

  6. CSS如何让DIV的宽度随内容的变化

    [css]CSS如何让DIV的宽度随内容的变化 让div根据内容改变大小 div{ width:auto; display:inline-block !important; display:inlin ...

  7. div 内容宽度自适应、超出后换行

    div 内容宽度自适应,超出后换行 { max-width:100%;width: fit-content;width: -webkit-fit-content;width: -moz-fit-con ...

  8. vue mounted中监听div的变化

    vue mounted中监听div的变化 <div style="width:200px;height:30px;background: #0e90d2" id=" ...

  9. div 自适应宽度

    div 自适应宽度 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

随机推荐

  1. Client does not support authentication protocol requested by server; consider upgrading MySQL client

    出现错误 Client does not support authentication protocol requested by server; consider upgrading MySQL c ...

  2. 出去就餐并且理解Express.js的基本知识

    Going out to eat and understanding the basics of Express.js出去就餐并且理解Express.js的基本知识 原文:Going out to e ...

  3. 2018-8-10-VisualStudio-修改配色

    title author date CreateTime categories VisualStudio 修改配色 lindexi 2018-08-10 19:16:52 +0800 2018-2-1 ...

  4. MacOS Mojave 安装sshpass

    使用sshpass的场景 安装sshpass及各种常见小问题处理 测试 安全提示 使用sshpass的场景 在MacOS下使用ansible命令(inventory文件中使用了密码验证的方式)或者使用 ...

  5. 构建游戏开发的大数据项目的流程demo图

  6. 系统符号二——正则表达式及三剑客之grep

    一基础正则表达式 (一)^  匹配以什么开头的信息 [root@centos71 ~]# grep "^root" /etc/passwd root:x:0:0:root:/roo ...

  7. 6398. 【NOIP2018模拟10.30】Generator(树状数组区间修改)

    题目描述 Description Input Output 输出 q 行,第 i 行表示数据 Di 的答案. Sample Input 4 3 2 1 1 2 4 2 1 2 1 1 3 5 2 2 ...

  8. linux运维、架构之路-HAProxy反向代理

    一.HAProxy介绍          专业反向代理,支持双机热备支持虚拟主机,配置简单,拥有非常不错的服务器健康检查功能,当其代理的后端节点出现故障, HAProxy会自动将该服务器摘除,故障恢复 ...

  9. 《x86汇编语言:从实模式到保护模式 》学习笔记之:第一次编写汇编语言

    1.汇编语言源文件:first.asm mov ax,0x3f add bx,ax add cx,ax 2.用nasm编译成二进制文件:first.bin nasm -f bin first.asm ...

  10. PHP入门培训教程 php中的时间处理

    php中的时间处理 PHP入门培训教程 兄弟连PHP培训 小编整理的 php中的时间处理: <? /** * 转换为UNIX时间戳 */ function gettime($d) { if(is ...