1.1介绍
在使用easyui的layout布局的时候,在某种情况下,我们会在后续的逻辑中修改一下layout的某个的高度,那么该怎么做呢?
在的代码进行控制,这样在页面初始化时候,内容的高度就得不到确定了,只能在js代码中去控制。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>easyui常见布局</title>
<link rel="stylesheet" href="./themes/default/easyui.css">
</head>
<style type="text/css">
.box{
width: 90%;
height: 50px;
border: 1px solid palevioletred;
margin: 5px;
}
</style>
<body>
<!-- 右侧内容区域 -->
<!-- <div data-options="region:'center',title:'右侧内容'" style="padding:5px;background:#eee;"></div> -->
<div class="easyui-layout" id="lay" style="width:100%;height:600px;">
<div id="p" data-options="region:'west'" title="West" style="width:20%;padding:10px">
<p>width:20%</p>
</div>
<div data-options="region:'center'" title="中间内容">
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
<div class="box">站位div</div>
</div>
</div>
<script src="./js/jquery.min.js" type="text/javascript"></script>
<script src="./js/jquery.easyui.min.js" type="text/javascript"></script>
<script src="./js/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$('#lay').layout();
setHeight();
});
//设置layout的自适应高度
function setHeight() {
var c = $('#lay');
var p = c.layout('panel', 'center');
var oldHeight = p.panel('panel').outerHeight();
p.panel('resize', { height: 'auto' });
var newHeight = p.panel('panel').outerHeight();
c.layout('resize', {
height: (c.height() + newHeight - oldHeight)
});
}
</script>
</body>
</html>