【问题标题】:Autohide a viewport's region in Extjs在 Extjs 中自动隐藏视口的区域
【发布时间】:2011-10-18 18:52:16
【问题描述】:

假设我有以下代码 sn-p:

Ext.create('Ext.container.Viewport', {
layout: 'border',
renderTo: Ext.getBody(),
items: [{
    region: 'north',
    html: '<h1 class="x-panel-header">Page Title</h1>',
    autoHeight: true,
    border: false,
    margins: '0 0 5 0'
}, {
    region: 'west',
    collapsible: true,
    title: 'Navigation',
    width: 150
    // could use a TreePanel or AccordionLayout for navigational items
}, {
    region: 'south',
    title: 'South Panel',
    collapsible: true,
    html: 'Information goes here',
    split: true,
    height: 100,
    minHeight: 100
}, {
    region: 'east',
    title: 'East Panel',
    collapsible: true,
    split: true,
    width: 150
}, {
    region: 'center',
    xtype: 'tabpanel', // TabPanel itself has no title
    activeTab: 0,      // First tab active by default
    items: {
        title: 'Default Tab',
        html: 'The first tab\'s content. Others may be added dynamically'
    }
}]
});

我想要做的是,当鼠标离开北方区域时,北方工具栏会自动隐藏,而当鼠标悬停在北方区域时,北方工具栏会自动隐藏(就像 Windows 开始菜单中的自动隐藏一样)

【问题讨论】:

    标签: extjs extjs4 viewport extjs3


    【解决方案1】:

    您可以使用折叠功能来实现此目的。创建一个替换标准 Header 的占位符:

    var placeHolder = Ext.create('Ext.panel.Panel', {
      height: 5,
      listeners: {
        mouseover : {
          element : 'el',
          fn : function(){
            //Expand the north region on mouseover
            Ext.getCmp('region-north').expand();
          }
        }
      }
    });
    

    将北部区域配置为可折叠并使用上面的占位符作为Collapsed-header-replacement:

    ...
    items: [{
      region: 'north',
      html: '<h1 class="x-panel-header">Page Title</h1>',
      autoHeight: true,
      border: false,
      id: 'region-north',
      margins: '0 0 5 0',
      collapsible: true,
      collapsed: true,
      placeholder: placeHolder,
      preventHeader: true,
      listeners: {
        mouseleave: {
          element: 'el',
          fn: function() {
            Ext.getCmp('region-north').collapse();
          }
        }
      }
    },
    ...
    

    这样你可以让 Ext 担心布局并保留折叠功能。

    【讨论】:

      【解决方案2】:

      创建一个面板,当鼠标不在它上面时,它的高度设置为 1px,当鼠标在它上面时,它的高度设置为 300px。

          Ext.create('Ext.panel.Panel',{
              renderTo : 'summary-div',
              height : 300, 
              listeners : {
                  mouseover : {
                      element : 'el',
                      fn : function(){
                          this.setHeight(300);
                      }
                  },
                  mouseleave : {
                      element : 'el',
                      fn : function(){
                          this.setHeight(1);
                      }
                  }
              }
          });
      

      【讨论】:

      • 您的解决方案是否会设置父面板的高度,在我的情况下是视口的北部区域?如果没有,那么我位于北部的工具栏将被隐藏,但该区域不会被隐藏.
      • 我的解决方案是指区域本身,因此将侦听器附加到作为面板的北部区域
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      相关资源
      最近更新 更多