- Ext JS 3.0 Cookbook
- Jorge Ramon
- 333字
- 2021-04-01 13:43:47
Maintaining components' proportions when their containers are resized
Having components that maintain their proportions when their containers are resized is important, especially, when dealing with form elements.
In the following screenshot, there are three panels that resize themselves as their container is resized:

How to do it...
- Create the panels that will be displayed:
panel1=new Ext.Panel({ title: 'Panel 1', html: 'Width=container width\' - 50 px', // Width=container width' - 50 px. anchor: '-50' }); panel2=new Ext.Panel({ title: 'Panel 2', html: 'Width=75% of container', // Width=75% of container. anchor: '75%' }); panel3=new Ext.Panel({ title: 'Panel 3', html: 'Width=50% of container<br/>Height=container\'s - 150 px', // Width=50% of container, // Height=container's - 150 px. anchor: '50%, -150' });
- Now, create the container window. When this window is resized, the panels will maintain their proportions:
var container=new Ext.Window({ title: 'Anchor Layout', width: 600, height: 350, defaults: { bodyStyle: 'padding:10px' }, // The anchored items will automatically resize // to maintain the same relative dimensions. layout: 'anchor', items: [panel1, panel2, panel3] }); container.show();
The relative anchoring is achieved by specifying an AnchorLayout
for the layout configuration option of the container. If the container is resized, all anchored items are automatically rendered according to their anchor rules.
The container using the AnchorLayout
can supply an anchoring-specific config
property, anchorSize
. By default, AnchorLayout
will calculate anchor measurements based on the size of the container itself. However, if anchorSize
is specified, the layout will use it as a virtual container for the purposes of calculating anchor measurements based on it instead. This will allow the container to be sized independent of the anchoring logic if necessary.
It's also possible to supply the horizontal and vertical anchor values through the anchor
config option. They can refer to the percentage an item should take up within its container, the offset from the right and bottom edges, or the container's sides. For example,'-50 75%'
would render the width offset from the container's right edge by 50 pixels and 75% of the container's height.
- AutoCAD 2010中文版基礎教程(第2版)
- HTML5 Multimedia Development Cookbook
- Getting Started with Microsoft Application Virtualization 4.6
- Midjourney AI繪畫藝術創作教程:關鍵詞設置、藝術家與風格應用175例
- 中文版3ds Max 2016/VRay效果圖制作實戰基礎教程
- Maya 2020基礎教材
- PHP 5 Social Networking
- Photoshop CS6從入門到精通
- PostgreSQL Replication
- Learning the Yahoo! User Interface library
- Creo 4.0中文版基礎教程
- Revit 2022中文版完全自學一本通
- Magento 1.4 Development Cookbook
- CorelDRA WX8中文版從入門到精通
- 從小白到高手:Studio One快速上手教程