• Ext.container.Viewport
  • Ext.panel.Panel

Viewport 它的布局会占用整个 body,也应该是这样,它会随着浏览器的高度和宽度的变化而变化。

Panel 布局时需要提供一定的高度和宽度值,这个值是固定的,它不会随着浏览器的变化而变化。

接下来,我来演示下,这两者布局的差异,也是我在工作时遇到的问题然后解决之:

html:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>博客管理</title>
<link href="../../Scripts/extjs/resources/css/ext-all-neptune.css" rel="stylesheet"
type="text/css" />
<link href="../../Scripts/Lib/Manage/Manage.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/extjs/ext-all.js" type="text/javascript"></script>
<script src="../../Scripts/extjs/ext-theme-neptune.js" type="text/javascript"></script>
<script src="../../Scripts/extjs/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../Scripts/Lib/Manage/Manage.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>

  

Viewport:

Ext.onReady(function () {
Viewport();
}); function Viewport() {
var viewport = Ext.create("Ext.container.Viewport", {
layout: {
type: 'border',
padding: '5',
},
items: [{
region: 'north',
height: 50,
border: false,
margin: '0,0,0,0',
bodyStyle: {
background: '#3992D4'
},
html: '<div class="header"><div class="title">优尔博客后台管理</div><div class="user">欢迎你:张威,<a href="#">退出</a></div></div>'
}, {
region: 'west',
title: '博客导航',
width: 250,
stateId: 'statePanelExample',
stateful: true,
split: true,
collapsible: true,
padding:'0',
layout: 'accordion',
items: [
{
title: '功能管理',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '文章管理', leaf: true, href: '#' },
{ id: '02', text: '标签管理', leaf: true, href: '#' },
{ id: '03', text: '用户管理', leaf: true, href: '#' }
]
}
}]
}, {
title: '博客设置',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '标题设置', leaf: true, href: '#' },
{ id: '02', text: '模板设置', leaf: true, href: '#' },
{ id: '03', text: '联系方式', leaf: true, href: '#' }
]
}
}]
}, {
title: '通知设置',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '通知设置', leaf: true, href: '#' }
]
}
}]
},{
title: '系统菜单',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '密码修改', leaf: true, href: '#' }
]
}
}]
}
]
}, {
region: 'center',
xtype: 'tabpanel',
id: 'MainTabPanel',
activeTab: 0,
items: {
title: '首页',
html: '<h1>欢迎使用优尔博客1.0系统</h1>'
}
}, {
region: 'south',
collapsible: false,
bodyStyle: {
background: '#3992D4'
},
html: '<div class="footer">© 合肥优尔电子科技有限公司 2014</div>',
split: false,
height: 22
}]
});
}

  

通过F12工具分析可知,Viewport确实占用整个body,

现在我们来看看Panel:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>博客管理</title>
<link href="../../Scripts/extjs/resources/css/ext-all-neptune.css" rel="stylesheet"
type="text/css" />
<link href="../../Scripts/Lib/Manage/Manage.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/extjs/ext-all.js" type="text/javascript"></script>
<script src="../../Scripts/extjs/ext-theme-neptune.js" type="text/javascript"></script>
<script src="../../Scripts/extjs/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../Scripts/Lib/Manage/Manage.js" type="text/javascript"></script>
</head>
<body>
<div id="container"></div>
</body>
</html>

  

.title{
text-align: left;
color: white;
font-weight: bold;
font-size: 30px;
margin: 0;
padding: 0;
padding-top: 5px;
width: 85%;
height: 100%;
float: left;
}
.footer {
text-align: center;
color: white;
font-weight: bold;
padding-top: 5px;
}
.user {
float: left;
color: white;
width:15%;
height: 100%;
font-size: 14px;
padding-top: 15px;
font-weight: bold;
}
.user a
{
margin-left: 10px;
color: white;
}
#container {
width: 1170px;
margin: 0 auto;
}

  

Ext.onReady(function () {
var panel= ExtPanel();
window.onresize = function() {
panel.setHeight(document.documentElement.clientHeight);
};

}); function ExtPanel() {
var pandel = Ext.create("Ext.panel.Panel", {
renderTo:'container',
width:1170,
height:document.documentElement.clientHeight,

layout: {
type: 'border',
padding: '5',
},
items: [{
region: 'north',
height: 50,
border: false,
margin: '0,0,0,0',
bodyStyle: {
background: '#3992D4'
},
html: '<div class="header"><div class="title">优尔博客后台管理</div><div class="user">欢迎你:张威,<a href="#">退出</a></div></div>'
}, {
region: 'west',
title: '博客导航',
width: 250,
stateId: 'statePanelExample',
stateful: true,
split: true,
collapsible: true,
padding:'0',
layout: 'accordion',
items: [
{
title: '功能管理',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '文章管理', leaf: true, href: '#' },
{ id: '02', text: '标签管理', leaf: true, href: '#' },
{ id: '03', text: '用户管理', leaf: true, href: '#' }
]
}
}]
}, {
title: '博客设置',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '标题设置', leaf: true, href: '#' },
{ id: '02', text: '模板设置', leaf: true, href: '#' },
{ id: '03', text: '联系方式', leaf: true, href: '#' }
]
}
}]
}, {
title: '通知设置',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '通知设置', leaf: true, href: '#' }
]
}
}]
},{
title: '系统菜单',
layout: 'fit',
items: [{
xtype: 'treepanel',
border: 0,
rootVisible: false,
root: {
expanded: true,
children: [
{ id: '01', text: '密码修改', leaf: true, href: '#' }
]
}
}]
}
]
}, {
region: 'center',
xtype: 'tabpanel',
id: 'MainTabPanel',
activeTab: 0,
items: {
title: '首页',
html: '<h1>欢迎使用优尔博客1.0系统</h1>'
}
}, {
region: 'south',
collapsible: false,
bodyStyle: {
background: '#3992D4'
},
html: '<div class="footer">© 合肥优尔电子科技有限公司 2014</div>',
split: false,
height: 22
}]
});
return pandel;
}

  

由此可知,利用renderTo将整个的panel放在container里,然后再设置container的width:1170px和margin:0 auto;就可以让它居中,

但是,是的,我说了但是,高度要有固定值,也就是说你设置panel的高度为:height:800,它就是800,这样设置好吗?

很显然这是行不通的,为什么?因为每个人的电脑显示器的屏幕显示率是有差异的,你这样设置成固定值,就有可能不是每台电脑都能正常显示,

有兴趣的可以自己试试。

不过这也是有解决方法的,就是利用“document.documentElement.clientHeight”来获取当前浏览器的可见区域显示高度,这样一来

就解决了刚才我们提到的问题。

不要高兴的太早,还有一个问题就是说,当你浏览器的宽度和高度变化时,因为你用“document.documentElement.clientHeight”

获取的高度也是个固定值,也就是说,它不是随着浏览器的变化而变化,这可不是我们想要的。

不过我们又有新的解决方法,这些方法都是有人在网上写好的,baidu一下就有可能搜到,不过 ,我把它串联起来,

这个代码是这样的:

var panel= ExtPanel();
window.onresize = function() {
panel.setHeight(document.documentElement.clientHeight);
};

利用window.onresize监听浏览器的变化,动态的设置Panel的高度,这样一来,所有问题全部解决!

ExtJs Ext.panel.Panel和Ext.container.Viewport布局问题的更多相关文章

  1. [转载]ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件

    作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...

  2. ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件

    本篇讲解三个容器类控件. 一.面板控件 Ext.Panel 一个面板控件包括几个部分,有标题栏.工具栏.正文.按钮区.标题栏位于最上面,工具栏可以在四个位置放置,围绕中间部分正文,按钮区位于最小方.下 ...

  3. Javascript - ExtJs - Ext.form.Panel组件

    FormPanel组件(Ext.form.FormPanel) logogram:Ext.form.Panel | xtype:form Ext.form.Panel.配置 frame }//旗下所有 ...

  4. Ext.tree.Panel Extjs 在表格中添加树结构,并实现节点移动功能

    最近在用Extjs 做后台管理系统,真的非常好用.总结的东西分享一下. 先展示一下效果图 好了,开始吧! 首先说一下我的创建结构: 一.构造内容 这个函数中包括store的创建,treePanel的创 ...

  5. ExtJs 学习之开篇(三)Ext.grid.Panel表格中的处理

    Ext.grid.Panel Ext.create('Ext.grid.Panel',{        title:'测试表格',        width:400,        height:20 ...

  6. Extjs学习笔记--Ext.tree.Panel

    Ext.create('Ext.tree.Panel', { title: 'Simple Tree', width: 200, height: 150, store: store, rootVisi ...

  7. 【extjs】 extjs5 Ext.grid.Panel 搜索示例

    先看效果图: 页面js: <script type="text/javascript"> /** * 日志类型 store * */ var logTypeStore ...

  8. 【extjs】 ext5 Ext.grid.Panel 分页,搜索

    带有分页,搜索的grid. <%@page language="java" contentType="text/html; charset=UTF-8" ...

  9. [Extjs] Ext4 Ext.grid.Panel 分页实现(mybatis 分页插件-PageHelper 使用)

    先看图: 页面js代码: var userStore=Ext.create('Ext.data.Store', { storeId:'userStore', fields:['uname', 'ema ...

随机推荐

  1. 五个在XML文档中预定义好的实体

    下面是五个在XML文档中预定义好的实体: < < 小于号 > > 大于号 & & 和 &apos; ' 单引号 " " 双引号 实体 ...

  2. PHP 点滴疑惑

    在数据库中,字段为NULL,可以使用empty()进行判断 <?php $CONFIG['hostname'] = 'localhost'; $CONFIG['username'] = 'roo ...

  3. JavaScript类型检测, typeof操作符与constructor属性的异同

    *#type.js function Person(name, age) { this.name = name; this.age = age; } var d = {an: 'object'}; v ...

  4. Memcached 工作原理

    http://hzp.iteye.com/blog/1872664 Memcached处理的原子是每一个(key,value)对(以下简称kv对),key会通过一个hash算法转化成hash-key, ...

  5. RabbitMQ 原文译1.2--"Hello Word"

    本系列文章均来自官网原文,属于个人翻译,如有雷同,权当个人归档,忽喷. .NET/C# RabbitMQ 客户端下载地址:https://github.com/rabbitmq/rabbitmq-do ...

  6. 20160515-hibernate--事务

    事务 JDBCTransaction 单个数据库(一个SesisonFactory对应一个数据库),由JDBC实现. Session session = null; Transaction tx =n ...

  7. oc语言学习之基础知识点介绍(四):方法的重写、多态以及self、super的介绍

    一.方法重写 /* 重写:当子类继承了父类的方法时,如果觉得父类的方法不适合,那么可以对这个方法进行重新实现,那么这个就重写. 注意:也就是说,一定只能发生在父类和子类关系中. 然后是子类重新实现父类 ...

  8. jQuery+php+ajax+PHPExcel实现上传excel文件导入数据库

            项目中需要批量导入数据,感觉这个需求以后也会经常用,必须总结分享下: 引入jquery的第三方表单插件: <scripttype="text/javascript&qu ...

  9. 编译个性化的openwrt固件

    基本流程是:下载openwrt源码(推荐attitude adjustment版本).执行feeds更新.make menuconfig(通过配置feed.conf.default和menuconfi ...

  10. someExperience

    // 面试题1 var name = 'World'; (function () { if (typeof name==='undefined') { var name = 'jack'; conso ...