我使用了Jquery Resizable组件,并且父div中有三个可调整大小的div。我需要适当调整所有三个div的大小,但是右侧面板和分离器存在问题。当您尝试调整大小时,它将以其他方式移动。我一直在努力寻找解决方案,但无法解决任何问题。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RickStrahl/jquery-resizable/master/src/jquery-resizable.js"></script>
<div class="page-container">
<div class="panel-container">
<div class="panel-left">
left panel
</div>
<div class="splitter">
</div>
<div class="panel-center">
center panel
</div>
<div class="splitter-right">
</div>
<div class="panel-right">
right panel
</div>
</div>
</div>
jQuery
$(".panel-left").resizable({
handleSelector: ".splitter",
resizeHeight: false
});
$(".panel-right").resizable({
handleSelector: ".splitter-right",
resizeHeight: false
});
答案 0 :(得分:0)
这是正在运行的演示。我对您的CSS和JS进行了更改。我使用JS创建了拆分器,并添加了onDragStart
函数来处理它
$(".panel-left,.panel-center")
.css({
/* required to allow resizer embedding */
position: "relative"
})
/* check .resizer CSS */
.prepend("<div class='resizer'></div>")
.resizable({
resizeHeight: false,
// we use the column as handle and filter
// by the contained .resizer element
handleSelector: "",
onDragStart: function(e, $el, opt) {
// only drag resizer
if (!$(e.target).hasClass("resizer"))
return false;
return true;
}
});
html,
body {
height: 100%;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
padding: 0;
margin: 0;
overflow: auto;
}
.page-container {
margin: 20px;
}
/* horizontal panel*/
.panel-container {
display: flex;
flex-direction: row;
border: 1px solid silver;
overflow: hidden;
/* avoid browser level touch actions */
xtouch-action: none;
}
.panel-left {
flex: 0 0 auto;
/* only manually resize */
padding: 10px;
width: 30%;
min-height: 200px;
white-space: nowrap;
background: #838383;
color: white;
}
.resizer {
position: absolute;
top: 0;
right: 0px;
bottom: 0;
left: auto;
width: 16px;
cursor: col-resize;
background: url(https://raw.githubusercontent.com/RickStrahl/jquery-resizable/master/assets/vsizegrip.png) center center no-repeat #535353;
}
.panel-center {
flex: 1 1 auto;
/* resizable */
padding: 10px;
width: 30%;
min-height: 200px;
background: #eee;
}
.panel-right {
flex: 1 1 auto;
/* resizable */
padding: 10px;
width: 30%;
min-height: 200px;
background: #eee;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RickStrahl/jquery-resizable/master/src/jquery-resizable.js"></script>
<div class="page-container">
<div class="panel-container">
<div class="panel-left">
left panel
</div>
<div class="panel-center">
center panel
</div>
<div class="panel-right">
right panel
</div>
</div>
</div>