如您所见,我有三个面板(左、中、右),它们可以正确地水平zoom /调整大小.现在,我想在中央面板内插入一个新面板.
新的面板将不得不垂直调整大小(上下升起).我想要实现这一点在纯的Java脚本(没有jQuery或其他库),根据我的Java脚本代码.我是新来的,我遇到了麻烦.
我想要得到这个:
附言:自然,3个垂直面板(左,中,右)必须继续左右水平移动,因为他们已经正确地移动与我的代码.我不希望新增加的面板打破了其他面板已经在运行的运动.
这是我的代码:
const gutters = document.querySelectorAll(".gutter");
const gutter_orizontal = document.querySelectorAll(".gutter_new");
const panes = document.querySelectorAll(".pane");
const minWidth = 200;
function resizer(e) {
window.addEventListener("mousemove", mousemove);
window.addEventListener("mouseup", mouseup);
let prevX = e.x;
const currentPane = e.currentTarget.parentNode;
const currentPanel = currentPane.getBoundingClientRect();
const prevPane = currentPane.previousElementSibling;
const prevPanel = prevPane.getBoundingClientRect();
function mousemove(e) {
let newX = prevX - e.x;
let newCurrentWidth = currentPanel.width + newX;
let newPrevWidth = prevPanel.width - newX;
if (newCurrentWidth < minWidth || newPrevWidth < minWidth) return;
currentPane.style.width = newCurrentWidth + "px";
prevPane.style.width = newPrevWidth + "px";
}
function mouseup() {
window.removeEventListener("mousemove", mousemove);
window.removeEventListener("mouseup", mouseup);
}
}
gutters.forEach((gutter) => gutter.addEventListener("mousedown", resizer));
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
}
.wrapper {
height: 100vh;
width: 100vw;
background: #333;
border: 6px solid #666;
display: flex;
}
.pane {
padding: 1em;
color: #fff;
min-width: 200px;
}
.center {
position: relative;
}
.right {
position: relative;
flex-grow: 1;
}
.new {
position: relative;
}
.gutter {
width: 10px;
height: 100%;
background: #666;
position: absolute;
top: 0;
left: 0;
cursor: col-resize;
}
.gutter_new {
height: 10px;
width: 100%;
background: #666;
position: absolute;
top: 0;
left: 0;
cursor: row-resize;
}
<div class="wrapper">
<div class="pane left">
This is the left pane.
</div>
<div class="pane center">
This is the center pane.
<div class="gutter"></div>
<div class="pane new">
This is the new pane.
<div class="gutter_new"></div>
</div>
</div>
<div class="pane right">
This is the right pane.
<div class="gutter"></div>
</div>
</div>