【问题标题】:IONIC2 Background image is resized when keyboard is openIONIC2背景图像在键盘打开时调整大小
【发布时间】:2017-07-16 19:55:53
【问题描述】:

在设置背景图像并且其大小(背景大小)设置为“覆盖”或“100% 100%”时使用 ionic-2,例如:

background: url("../../img/bg.jpeg");
background-repeat: no-repeat;
background-size: cover;

当键盘打开时,背景图像被调整大小,如何避免这种情况? (这样即使键盘缩小了内容,背景图像的大小也保持不变)

【问题讨论】:

  • 嗨@Dinana,尽量使背景位置固定,高度为100%。对我来说它有效。
  • 如果你不需要调整背景图片的大小,它可以工作,否则它不会..

标签: android css background keyboard ionic2


【解决方案1】:

使用正确的方式嵌入全屏背景图片:

ion-content { 
  background: url(images/bg.jpg) no-repeat center center fixed; 
  background-size: cover;
} 

【讨论】:

    【解决方案2】:

    在找了很久没有解决方案后,我决定使用 angular-2 的 ngStyle 开发一个,解决方案其实很简单:

    在页面类中,创建 shouldHeight 成员:

    export class myPage {
      shouldHeight = document.body.clientHeight + 'px' ;
    
      constructor(private navCtrl: NavController) {
          
      }
    
    }

    然后将其添加到所述页面中的离子内容中:

    <ion-content padding [style.background-size]="'100% ' + shouldHeight">

    【讨论】:

      猜你喜欢
      • 2017-02-25
      • 2019-11-17
      • 1970-01-01
      • 1970-01-01
      • 2015-06-18
      • 2011-07-15
      • 2011-05-16
      • 2013-02-14
      • 2015-07-05
      相关资源
      最近更新 更多