zoukankan      html  css  js  c++  java
  • 移动端点击输入框,弹出键盘,底部被顶起问题(vue)

    
    

    这个问题相信做移动端开发的童鞋会有深刻体会,以前用jq开发时就很头疼这个问题,每次底部footer部分需要用position:fixed,如果页面内容不是很长,没有超出屏幕范围,那就还好,没有问题;一旦超出屏幕范围,当你点击输入框,弹出键盘时,底部固定定位的footer部分就会被顶起来,很丑!有木有。

    在键盘弹起时,页面高度变小,底部固定定位上升,所以我们只需要在页面高度变小时,隐藏底部footer部分,当键盘消失时再显示底部footer部分就可以解决问题了。

    解决方法:检测浏览器的resize事件,当高度过小时就可以判定为出现这种情况,这时把定位改成absolute或者直接隐藏掉之类的。

    第一步: 先在 data 中去 定义 一个记录高度是 属性

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

    第二步: 我们需要将 reisze 事件在 vue mounted 的时候 去挂载一下它的方法

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

      

    第三步:watch监控比较,判断按钮是否该显示出来

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

    第四步:在模板中给footer添加v-show

    <div class="footer" v-show="hidshow">
          <div class="footerBtn">核验</div>
    </div>
    

      

  • 相关阅读:
    R-FCN、SSD、YOLO2、faster-rcnn和labelImg实验笔记
    yolov3的anchor机制与损失函数详解
    CV资料推荐
    测试用例设计方法总结
    测试需求分析
    bug生命周期
    linux命令一
    linux 命令二
    linux 命令三
    mysql数据库和禅道安装
  • 原文地址:https://www.cnblogs.com/ruthless/p/9299974.html
Copyright © 2011-2022 走看看