Extjs中layout:column的布局,容器大小使用百分比,不能自适应(自动缩放)

21 篇文章 0 订阅

在Extjs中,用layout:column的布局,window或panel大小设为百分比,里面的控件不随容器大小而改变(自动缩放)。

如下:

            <link rel="stylesheet" type="text/css" href="./extjs/resources/css/ext-all.css" />
            <script type="text/javascript" src="./extjs/adapter/ext/ext-base.js"></script>
            <script type="text/javascript" src="./extjs/ext-all-debug.js"></script>
            <script type="text/javascript" src="./extjs/examples.js"></script>

            <script type="text/javascript">
                Ext.onReady(function(){
                    Ext.QuickTips.init();

                    new Ext.FormPanel({
                        renderTo:document.body,frame:true,id:'twindow',
                        title: '布局测试',labelAlign: 'right',
                        plain:true,layout:"form",
                        items: [{layout:"column",baseCls:"x-plain",style:"padding:5px",
                                items:[{columnWidth:.5,layout: 'form',
                                        items: [{
                                                xtype:'textfield',
                                                fieldLabel: 'First Name',
                                                name: 'first',
                                                anchor:'95%'
                                            }, {
                                                xtype:'textfield',
                                                fieldLabel: 'Company',
                                                name: 'company',
                                                anchor:'95%'
                                            }]
                                    },{columnWidth:.5,layout: 'form',
                                        items: [{
                                                xtype:'textfield',
                                                fieldLabel: 'Last Name',
                                                name: 'last',
                                                anchor:'95%'
                                            },{
                                                xtype:'textfield',
                                                fieldLabel: 'Email',
                                                name: 'email',
                                                vtype:'email',
                                                anchor:'95%'
                                            }]
                                    }]
                            }],

                        buttons: [{text: 'Save'},{text: 'Cancel'}]
                    });
                });
            </script>
解决方式如下:

                });
            </script>

前加入下面代码

                    window.onresize = function() {
                        var myWidth = 0, myHeight = 0;
                        if (typeof (window.innerWidth) == 'number') {
                            //Non-IE
                            myWidth = window.innerWidth;
                            myHeight = window.innerHeight;
                        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                            //IE 6+ in 'standards compliant mode'
                            myWidth = document.documentElement.clientWidth;
                            myHeight = document.documentElement.clientHeight;
                        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                            //IE 4 compatible
                            myWidth = document.body.clientWidth;
                            myHeight = document.body.clientHeight;
                        }
                        var w = Ext.getCmp('twindow');
                        w.setPosition(0, 0);
                        w.setWidth(myWidth);
                        //w.setSize(myWidth, myHeight);
                    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值