zoukankan      html  css  js  c++  java
  • vue移动端安卓机上键盘弹起时把底部菜单顶起来

    1. ios和安卓的键盘弹起方式不同, ios直接弹出键盘, 不影响页面, 而安卓键盘弹起时会把页面顶起来, 这样就会把底部菜单顶起来了, 绝对定位也没用;

    2. 解决思路: 页面进来时获取默认的屏幕高度, 定义一个值, 用来监听实时屏幕的高度, 当实时屏幕高度小于默认高度时, 说明键盘弹起来了, 这时就隐藏底部菜单, 当键盘收起时, 再显示底部菜单;

    3. 具体代码:
      (1) 在data中定义默认值
      data() {
      return {
      docmHeight: document.documentElement.clientHeight, //默认屏幕高度
      showHeight: document.documentElement.clientHeight, //实时屏幕高度
      hidshow:true, //显示或者隐藏footer,
      isResize:false //默认屏幕高度是否已获取
      };
      },

      (2) 在mounted中获取屏幕高度
      mounted() {
      window.onresize = ()=>{
      return(()=>{
      if (!this.isResize) {
      //默认屏幕高度
      this.docmHeight = document.documentElement.clientHeight;
      this.isResize = true;
      }
      //实时屏幕高度
      this.showHeight = document.body.clientHeight;
      console.log(this.showHeight);
      })()
      }
      },

      (3) 用watch监听屏幕高度变化, 控制底部菜单的显示隐藏
      watch: {
      showHeight() {
      if(this.docmHeight >= this.showHeight){
      this.hidshow = false
      }else{
      this.hidshow = true
      }
      console.log(this.hidshow);
      }
      },

  • 相关阅读:
    Androidの多线程之多线程用法大集合(未整理)
    Androidの多线程之更新ui(Thread+Handler+Message)
    构建之法阅读笔记1
    文件与流
    公文流转系统一
    JAVA web课堂测试1
    10.21动手动脑
    Android学习02
    Android学习01
    Android学习03
  • 原文地址:https://www.cnblogs.com/Shysun/p/11584262.html
Copyright © 2011-2022 走看看