【问题标题】:It possible to get the height of the ion-footer?可以得到离子脚的高度吗?
【发布时间】:2018-03-16 20:50:54
【问题描述】:

我正在尝试将初始窗口高度减去离子页脚高度。 我成功了,但获得窗口高度仍然有页脚高度。 有可能得到 ion-footer ionic2 元素的高度吗?

我不需要得到离子含量的高度

<ion-footer>
  <button type="submit" form="loginForm" ion-button block class="rnb-button" [disabled]="!loginForm.valid">Log In</button>
</ion-footer>

TS

this.gridHeight = window.innerHeight;

我需要什么

this.gridHeight = window.innerHeight - footerHeight;

谢谢。

【问题讨论】:

  • 您尝试了什么,什么没有奏效?
  • 我正在尝试将离子网格高度设置为在键盘打开后等于离子含量高度。因为一旦打开键盘,离子含量高度就会改变,解决方案是 window.innerHeight 减去 ion-footer 高度
  • 是的,但我的意思是,您尝试了哪些代码来获取页脚高度?结果如何不符合您的预期?
  • 我没有尝试任何代码来获取我问这个问题的离子页脚,因为我不知道如何获得离子页脚高度。只是我使用 window.innerHeight 得到窗口高度
  • 给我们你声明了 ion-footer 的代码。请使用 HTML 和 TS。

标签: angular typescript ionic2 ionic3


【解决方案1】:

是的,您可以使用对内容的引用来使用contentBottom 属性获取页脚的高度:

contentBottom: 一个数字,表示底部有多少像素 内容已被调整,可以通过填充或 利润。 此调整是为了考虑到 页脚

import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';

@Component({...})
export class MyPage{
  @ViewChild(Content) content: Content;

  ionViewDidEnter() {
    if(this.content) {
      console.log(`Footer height: ${this.content.contentBottom}`);
    }
  }
}

编辑:

这只是一个建议,但您应该使用platform 来获取该信息,而不是使用window.innerHeight,因为:

在幕后platform 使用window.innerWidthwindow.innerHeight 但最好使用这种方法,因为 维度是一个缓存值,它减少了多次和 昂贵的 DOM 读取

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';

@Component({...})
export MyApp {
  constructor(platform: Platform) {
    platform.ready().then((readySource) => {
      console.log('Width: ' + platform.width());
      console.log('Height: ' + platform.height());
    });
  }
}

【讨论】:

  • 如何在自定义组件中执行此操作?当我尝试使用 @ViewChild(Content) content: Content; .. 然后将其注销时,我得到未定义。
  • 我认为你不能这样做。你想达到什么目的?也许还有另一种方法...
  • 我正在尝试创建一个自定义的可拖动抽屉组件,该组件采用页脚类型的位置,为此我需要知道组件内content.contentBottom 的值...必须有一个无需将内容作为输入传递的方法,因为ion-footer 也是如此。
  • @juliusbangert 你的意思是什么like this
  • 是的,我正在调整该教程中的概念以使其更通用,例如我希望它自动使用或不使用标签栏。
猜你喜欢
  • 1970-01-01
  • 2017-12-25
  • 1970-01-01
  • 1970-01-01
  • 2020-10-20
  • 1970-01-01
  • 2016-12-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多