Vue项目中移动端点击输入框,软键盘弹出,导致底部按钮被顶起问题

853 阅读1分钟

当我们用positon:fixed,定位一个按钮在底部,页面中存在输入框,当输入框获取焦点后,固定定位的内容被顶上来了,影响页面。

解决方案:我们可以通过浏览器的resize事件,监测页面高度,来决定隐藏或显示子控键。

解决步骤:

一、先在data中定义用到的属性

data(){

    return {

        documentHeight:document.documentElement.clientHeight,//初始化进入,默认的屏幕高度

        showHeight:document.documentElement.clientHeight,//实时的屏幕高度

        isShow:true,//显示或隐藏footer

    }

}

二、在vue mounted时将resize事件挂载上

mounted(){

//window.onresize监听页面高度的变化

window.onresize=()=>{

    return( ()=>{

      //实时屏幕高度

        this.showHeight=document.body.clientHeight;

    } )()

 }

}

三、watch监控比较,判断按钮是否显示

watch(){

    showHeight:()=>{

      if(this.documentHeight>this.showHeight){

           this.isShow=false;

       }else{

          this.isShow=true;

       }

    }

}