移动端H5页面-微信内浏览器软键盘弹起input失焦后不回弹

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_36710522/article/details/102736855

场景:IOS微信内置浏览器在打开H5页面的时候,input输入时软键盘弹起,页面会被顶起来,软键盘收起的时候页面不回弹
出现的条件为
页面高度过小&&聚焦时,页面需要往上移动的时候
解决:(以vantUI的输入框为例)给输入框添加一个失去焦点的事件
在这里插入图片描述

 //解决微信端页面被顶起
    temporaryRepair() {
      let currentPosition, timer;
      let speed = 1; //页面滚动距离
      timer = setInterval(function() {
        currentPosition =
          document.documentElement.scrollTop || document.body.scrollTop;
        currentPosition -= speed;
        window.scrollTo(0, currentPosition); //页面向上滚动
        currentPosition += speed;
        window.scrollTo(0, currentPosition); //页面向下滚动
        clearInterval(timer);
      }, 1);
    },

另外其他方法:

<template>
  <input type="text" @focus="focus" @blur="blur">
</template>

<script>
  export default {
    data() {
      return {
        scrollTop: 0
      }
    },
    
    methods: {
      focus() {
        this.scrollTop = document.scrollingElement.scrollTop;
      },
      
      blur() {
        document.scrollingElement.scrollTo(0, this.scrollTop);
      }
    }
  }
</script>

猜你喜欢

转载自blog.csdn.net/qq_36710522/article/details/102736855
今日推荐