移动端点击输入框,键盘把底部的内容顶起

今天遇到这样一个问题:手机端输入表单信息时,键盘把底部的按钮顶起,这样就把一部分表单遮盖住了。
详情如下图:
在这里插入图片描述
在这里插入图片描述
可以看到,详细地址被遮盖住了,这样的用户体验肯定不好,解决办法如下:
通过将实时屏幕高度和默认屏幕高度进行比较,如果实时屏幕的高度大于默认屏幕高度,就将按钮隐藏,否则就显示按钮。
具体实现如下:
1.将底部设置为fixed

    <div class="footer" v-show="hidshow">
      <a @click="save">保存地址</a>
    </div>
    
.footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 1.3rem;
  border-top: 1px solid #e0e0e0;
  background: #ffffff;

  a {
    display: block;
    margin: 0.18rem auto;
    text-align: center;
    width: 95%;
    height: 0.9rem;
    line-height: 0.9rem;
    border-radius: 0.45rem;
    font-size: 0.28rem;
    color: #fff;
    background-color: #17C169;
  }
}

2.在data中定义两个高度,分别是实时屏幕高度和默认屏幕高度

  data () {
    return {
      docmHeight: document.documentElement.clientHeight,  //默认屏幕高度
      showHeight: document.documentElement.clientHeight,   //实时屏幕高度
      hidshow:true  //显示或者隐藏footer
    };
  },

3.在mounted里面进行监听

  mounted(){
    // window.onresize监听页面高度的变化
    window.onresize = ()=>{
        return(()=>{
            this.showHeight = document.body.clientHeight;
        })()
    }
  },

4.用watch监控比较,判断按钮是否显示出来

  watch:{
    showHeight:function() {
        if(this.docmHeight > this.showHeight){
            this.hidshow=false
        }else{
            this.hidshow=true
        }
    }
  }

这样就能很好的解决移动端点击输入框,键盘把底部的内容顶起这个问题了。

感谢我以为你不在乎这位朋友的帮助。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值