左右拖拽条改变大小

<!DOCTYPE html>

<html>

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>demo</title>

<style>

ul,

li {

margin: 0;

padding: 0;

}

 

body {

font: 14px/1.5 Arial;

color: #666;

box-sizing: border-box;

margin: 0;

padding: 0;

}

 

#box {

position: relative;

width: 100%;

height: 600px;

border: 1px solid #000;

margin: 10px auto;

overflow: hidden;

}

 

#box ul {

list-style-position: inside;

margin: 10px;

}

 

#top,

#bottom {

color: #FFF;

height: 100%;

overflow: hidden;

}

 

#top {

position: absolute;

width: 219px;

background: green;

}

 

#bottom {

width: 100%;

background: skyblue;

}

 

#line {

position: absolute;

top: 0;

left: 219px;

height: 100%;

width: 4px;

overflow: hidden;

background: red;

cursor: w-resize;

}

</style>

<script>

function $(id) {

return document.getElementById(id)

}

window.onload = function () {

var oBox = $("box"),

oTop = $("top"),

oBottom = $("bottom"),

oLine = $("line");

oLine.onmousedown = function (e) {

var disX = (e || event).clientX;

console.log(disX);

oLine.left = oLine.offsetLeft;

document.onmousemove = function (e) {

var iT = oLine.left + ((e || event).clientX - disX);

// var e = e || window.event;

// tarnameb = e.target || e.srcElement;

// var maxT = oBox.clientWight - oLine.offsetWidth;

oLine.style.margin = 219;

iT < 219 && (iT = 219);

// iT > maxT && (iT = maxT);

oLine.style.left = oTop.style.width = iT + "px";

console.log(oTop.style.width)

// oBottom.style.width = oBox.clientWidth - iT + "px";

return false

};

document.onmouseup = function () {

console.log('11111')

document.onmousemove = null;

document.onmouseup = null;

oLine.releaseCapture && oLine.releaseCapture()

};

// oLine.setCapture && oLine.setCapture();

// console.log(oLine.setCapture())

return false

};

};

</script>

</head>

 

<body>

<div id="box">

<div id="top">

</div>

<div id="bottom">

</div>

<div id="line"></div>

</div>

</body>

 

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用`vue-draggable-resizable`插件来实现拖动调整左右两侧div的宽度。 首先在项目中安装`vue-draggable-resizable`: ``` npm install vue-draggable-resizable --save ``` 然后在需要使用的组件中引入: ```javascript import VueDraggableResizable from 'vue-draggable-resizable' import 'vue-draggable-resizable/dist/VueDraggableResizable.css' ``` 接着在组件中使用`vue-draggable-resizable`: ```html <template> <div> <vue-draggable-resizable :w="leftWidth" :h="height" :x="0" :y="0" :min-width="minWidth" :max-width="maxWidth" :parent="true" :active="true" :grid="[1, 1]" :handles="['e']" @resize="onResize" > <div class="left"></div> </vue-draggable-resizable> <div class="divider"></div> <div class="right"></div> </div> </template> <script> import VueDraggableResizable from 'vue-draggable-resizable' import 'vue-draggable-resizable/dist/VueDraggableResizable.css' export default { components: { VueDraggableResizable }, data() { return { leftWidth: 200, height: 500, minWidth: 100, maxWidth: 400 } }, methods: { onResize() { // 当左侧div宽度改变时触发 } } } </script> ``` 在上面的代码中,我们使用了`vue-draggable-resizable`组件来实现拖动调整左侧div的宽度。具体的参数和事件如下: - `w`:左侧div的宽度 - `h`:左侧div的高度 - `x`:左侧div的x坐标 - `y`:左侧div的y坐标 - `min-width`:左侧div的最小宽度 - `max-width`:左侧div的最大宽度 - `parent`:是否限制在父元素内 - `active`:是否活动状态 - `grid`:拖拽的网格大小 - `handles`:拖拽的手柄位置 - `@resize`:左侧div改变宽度时触发的事件 通过设置`handles`为`['e']`,表示只能横向拖动调整宽度,而不能改变高度。当左侧div的宽度改变时,会触发`@resize`事件,在事件处理函数中可以实现相应的逻辑。 最后,为了实现左右两侧div并排显示,需要在样式中设置: ```css .left { float: left; height: 100%; background-color: #f0f0f0; } .right { float: left; height: 100%; width: calc(100% - 200px); background-color: #e0e0e0; } .divider { float: left; height: 100%; width: 10px; background-color: #d0d0d0; } ``` 这样就可以实现拖动调整左右两侧div的宽度了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值