
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
</head>
<body>
<div id="weiMain">
<div id="weiLeft">
左侧边栏区域
</div>
<div id="weiLeftResize" title="收缩markdown侧边栏">
<button onclick="leftDragControllerDivVisiable();return false;" class="weiresizeBtn">=</button>
</div>
<div id="weiContent">
<div id="weiMarkdownContent">内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域</div>
</div>
<div id="weiRightResize" title="收缩markdown侧边栏">
<button onclick="rightDragControllerDivVisiable();return false;" class="weiresizeBtn weiresizeBtnRight">= </button>
</div>
<div id="weiRight">
右侧边栏区域
</div>
</div>
</body>
</html>
<style>
* {
margin: 0;
padding: 0;
}
:root {
--leftWidth: 15%;
--leftBorderRightColor: red;
--leftResizeWidth: 10px;
--leftResizeBgHover: aqua;
--rightWidth: 15%;
--rightBorderRightColor: red;
--rightResizeWidth: 10px;
--rightResizeBgHover: aqua;
}
#weiMain {
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
#weiMain>div {
position: absolute;
}
#weiLeft {
width: var(--leftWidth);
height: 100%;
left: 0;
top: 0;
border-right: 1px solid var(--leftBorderRightColor);
box-sizing: border-box;
}
#weiRight {
width: var(--rightWidth);
height: 100%;
right: 0;
top: 0;
border-left: 1px solid var(--rightBorderRightColor);
box-sizing: border-box;
}
#weiLeftResize {
width: var(--leftResizeWidth);
height: 100%;
left: var(--leftWidth);
top: 0;
z-index: 999;
}
#weiRightResize {
width: var(--rightResizeWidth);
height: 100%;
right: var(--rightWidth);
top: 0;
z-index: 999;
}
#weiLeftResize:hover,
#weiRightResize:hover {
background-color: var(--leftResizeBgHover);
cursor: col-resize;
}
#weiContent {
width: 100%;
height: 100%;
padding-left: calc(var(--leftWidth) + var(--leftResizeWidth));
padding-right: calc(var(--rightWidth) + var(--rightResizeWidth));
z-index: -99;
box-sizing: border-box;
}
.weiresizeBtn {
position: absolute;
bottom: 0;
box-sizing: 99999;
width: 20px;
height: 20px;
}
.weiresizeBtnRight{
right: 0;
}
</style>
<script>
function leftDragControllerDiv(main = "#weiMain", sidebar = "#weiLeft", resize = "#weiLeftResize", content = "#weiContent", minleft = 0, minright = 0) {
var resize = document.querySelector(resize);
var left = document.querySelector(sidebar);
var mid = document.querySelector(content);
var box = document.querySelector(main);
resize.onmousedown = function (e) {
var startX = e.clientX;
resize.left = resize.offsetLeft;
document.onmousemove = function (e) {
var endX = e.clientX;
var moveLen = resize.left + (endX - startX);
var maxT = box.clientWidth - resize.offsetWidth;
if (moveLen < minleft) moveLen = minleft;
if (moveLen > maxT - minright) moveLen = maxT - minright;
console.log(moveLen);
left.style.width = moveLen + 'px';
resize.style.left = moveLen + 'px';
mid.style.paddingLeft = (moveLen + resize.offsetWidth) + 'px';
};
document.onmouseup = function (evt) {
document.onmousemove = null;
document.onmouseup = null;
resize.releaseCapture && resize.releaseCapture();
};
resize.setCapture && resize.setCapture();
return false;
};
}
function leftDragControllerDivVisiable(main = "#weiMain", sidebar = "#weiLeft", resize = "#weiLeftResize", content = "#weiContent", minleft = 0, minright = 0) {
var resize = document.querySelector(resize);
var left = document.querySelector(sidebar);
var mid = document.querySelector(content);
var box = document.querySelector(main);
if (resize.left <= minleft) {
console.log(1);
const root = document.documentElement;
const leftWidth = window.getComputedStyle(root).getPropertyValue('--leftWidth');
left.style.width = leftWidth;
resize.style.left = leftWidth;
mid.style.paddingLeft = leftWidth;
} else {
left.style.width = 0;
resize.style.left = 0;
mid.style.paddingLeft = (0 + resize.offsetWidth) + 'px';
}
}
function rightDragControllerDiv(main = "#weiMain", sidebar = "#weiRight", resize = "#weiRightResize", content = "#weiContent", minleft = 0, minright = 0) {
var right = document.querySelector(sidebar);
var mid = document.querySelector(content);
var box = document.querySelector(main);
var resize = document.querySelector(resize);
resize.onmousedown = function (e) {
var startX = e.clientX;
resize.left = resize.offsetLeft;
document.onmousemove = function (e) {
var endX = e.clientX;
var moveLen = resize.left + (endX - startX);
var maxT = box.clientWidth - resize.offsetWidth;
if (moveLen < minleft) moveLen = minleft;
if (moveLen > maxT - minright) moveLen = maxT - minright;
resize.style.right = (box.clientWidth - (moveLen + resize.offsetWidth)) + 'px';
right.style.width = (box.clientWidth - (moveLen + resize.offsetWidth)) + 'px';
mid.style.paddingRight = (box.clientWidth - (moveLen + resize.offsetWidth)) + 'px';
};
document.onmouseup = function (evt) {
document.onmousemove = null;
document.onmouseup = null;
resize.releaseCapture && resize.releaseCapture();
};
resize.setCapture && resize.setCapture();
return false;
};
}
function rightDragControllerDivVisiable(main = "#weiMain", sidebar = "#weiRight", resize = "#weiRightResize", content = "#weiContent", minleft = 0, minright = 0) {
var right = document.querySelector(sidebar);
var mid = document.querySelector(content);
var box = document.querySelector(main);
var resize = document.querySelector(resize);
if (mid.style.paddingRight == minright + 'px') {
const root = document.documentElement;
const rightWidth = window.getComputedStyle(root).getPropertyValue('--rightWidth');
var maxT = box.clientWidth - rightWidth
console.log( box.clientWidth , rightWidth);
resize.style.right = right.style.width = mid.style.paddingRight =rightWidth ;
} else {
resize.style.right = right.style.width = mid.style.paddingRight =0 ;
}
}
leftDragControllerDiv();
rightDragControllerDiv();
</script>
<style>
</style>

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246