ExtJs Ext.panel.Panel和Ext.container.Viewport布局问题

简介: Ext.container.Viewport Ext.panel.Panel Viewport 它的布局会占用整个 body,也应该是这样,它会随着浏览器的高度和宽度的变化而变化。 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的高度,这样一来,所有问题全部解决!

目录
相关文章
|
Linux Anolis
性能优化特性之:EXT4 Fast Commit
本文介绍了倚天实例上进行IO优化的特性:Fast Commit,并对其优化原理、使用方法进行了详细阐述
|
安全 项目管理
一文搞懂需求流程规范的制定方法和落地技巧
随着业务和产品的发展、团队的不断扩大,很多团队都不可避免的会遇到需求流程混乱的问题。虽然有的团队也编写了一些“需求流程规范”的文档,但最终却流于纸面,难以在团队真正落地。如何科学制定并有效落实需求管理规范呢?对此,云效产品经理陈逊进行了非常详细的直播分享,本文是他经验的文字总结。
103540 19
|
6月前
|
运维 Serverless 云计算
Serverless,云计算3.0阶段
Serverless是一种云计算服务模式,让开发者只需专注于编写业务逻辑代码,无需管理底层基础设施如服务器、存储和网络。相比传统Serverful架构,Serverless降低了运维成本,提高了开发效率,并通过弹性伸缩应对流量峰谷,按实际资源消耗付费,显著降低资源浪费和费用开销。
213 3
Serverless,云计算3.0阶段
|
开发工具 git 缓存
Git忽略规则.gitignore不生效
在项目开发过程中个,一般都会添加 .gitignore 文件,规则很简单,但有时会发现,规则不生效。 原因是 .gitignore 只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
60678 4
|
算法 Shell 计算机视觉
BeiT v2 来袭 | BeiT升级,全面超越 MAE,实现 Vision Transformer 微调自由!
BeiT v2 来袭 | BeiT升级,全面超越 MAE,实现 Vision Transformer 微调自由!
1174 0
BeiT v2 来袭 | BeiT升级,全面超越 MAE,实现 Vision Transformer 微调自由!
|
10月前
|
应用服务中间件 网络安全 nginx
轻松上手Nginx Proxy Manager:安装、配置与实战
Nginx Proxy Manager (NPM) 是一款基于 Nginx 的反向代理管理工具,提供直观的 Web 界面,方便用户配置和管理反向代理、SSL 证书等。本文档介绍了 NPM 的安装步骤,包括 Docker 和 Docker Compose 的安装、Docker Compose 文件的创建与配置、启动服务、访问 Web 管理界面、基本使用方法以及如何申请和配置 SSL 证书,帮助用户快速上手 NPM。
6754 1
ly~
|
12月前
|
传感器 存储 供应链
大数据在供应链管理中的具体应用案例
在供应链管理中,大数据的应用显著提升了效率与预测准确性。例如,沃尔玛利用销售数据与外部信息如天气预报,实现精准需求预测,提前调配应急物资,既满足顾客需求又减少库存积压。亚马逊则通过分析商品入库时间、销售速度等数据,优化库存水平,确保畅销品备货充足,小众品库存灵活,从而降低运营成本。DHL借助运输工具上的传感器收集的数据,优化物流路线,避免拥堵并合理装载货物,同时预测设备故障,减少物流延误,提升整体运输效率。
ly~
1607 2
解决 Error: Node Sass version 6.0.1 is incompatible with ^4.0.0.
解决 Error: Node Sass version 6.0.1 is incompatible with ^4.0.0.
1042 0