简体   繁体   English

如何使用ExtJs制作100%高度和宽度的窗口?

[英]How can I make a window in 100% height and width with ExtJs?

This one didn't work: 这一个不起作用:

new Ext.Window({
    width:'100%',
    height: '100%'
}).show();

I has do be fluid, so that when the window is resized it has to change its diemensions. 我确实很流畅,所以当调整窗口大小时,它必须改变它的尺寸。

This can only be achieved by monitoring window.resize event. 这只能通过监视window.resize事件来实现。

Ext.onReady(function() {
    var win = new Ext.Window({
        draggable: false
    });

    win.show();

    win.setSize(Ext.getBody().getViewSize());
    win.setPagePosition(0, 0);
    Ext.fly(window).on('resize', function(e, w) {
        win.setSize(Ext.getBody().getViewSize());
        win.setPagePosition(0, 0);
    });
});

Notice that my example works properly if body has overflow: hidden . 请注意,如果bodyoverflow: hidden ,我的示例可以正常工作overflow: hidden Otherwise unwanted scrollbars will be shown. 否则将显示不需要的滚动条。

Check out this fiddle . 看看这个小提琴

This can also be achieved by creating a Viewport, which is designed to do exactly what you're asking. 这也可以通过创建一个视口来实现,该视口旨在完全按照您的要求进行操作。 Here's a quick example, and it shows that you don't need to specify any heights/widths: 这是一个简单的例子,它表明您不需要指定任何高度/宽度:

Ext.onReady(function(){

    var thisView = new Ext.Viewport({
        layout:'anchor',
        items:[
            {   title: 'Section 1'
                ,html: 'some content'
            }
            ,{  title: 'Section 2'
                ,html: 'some more content'
            }
        ]
    });

});

You'll note that you don't even need to "show" it. 你会注意到你甚至不需要“显示”它。

EDIT: Oh, I meant to also remark that if you add some longer content into those html sections, you'll see that if you resize your browser window, they will change their heights automatically to let all the content be seen. 编辑:哦,我还想说,如果你在这些html部分添加一些更长的内容,你会发现如果你调整浏览器窗口的大小,他们会自动改变他们的高度,让所有内容都被看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM