Top
Fork me on Gitee

h5 android 个别机型, fixed 布局被软键盘顶上去,遮挡输入框

原因:html、body设置了 height: 100% 的自适应布局后,高度跟随屏幕的可用高度改变而改变导致的。

解决办法:

1、不使用 fixed 定位,使用替代方案(推荐):

a:使用 position:absolute; overflow-y:scroll;

b:使用 display:flex; overflow-y:scroll;

其中,a方案内容区域的高度通过js控制;b方案内容区域的高度通过flex布局自动排版;

2、根据输入框获取焦点与失去焦点事件切换 fixed 定位与 static 定位

也可以根据软键盘是否弹起,是否改变屏幕可用高度,来改变 定位方式 或 显示隐藏 fixed定位元素

docmHeight: document.documentElement.clientHeight,  // 默认屏幕高度
showHeight: document.documentElement.clientHeight,   // 实时屏幕高度
hideshow: true // 显示或者隐藏
// 监听
watch:{
  showHeight: function() {
    if(this.docmHeight > this.showHeight) {
        this.hideshow = false
    } else {
        this.hideshow = true
    }
  }
}
posted @ 2022-03-03 17:45  lisashare  阅读(2007)  评论(0编辑  收藏  举报