左右拖拽條改變大小
<!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>