解决移动端Ios,当点击input键盘弹起再收起导致页面顶部部分遮挡, Ios端微信公众号,app,浏览器

  1.  

    调用页面的input标签
    //html
    <input type="number"@blur="loseFocus" />

    //js
    判断是否是微信端
    isWeiXin() {
    const isWeiXin = window.navigator.userAgent.toLowerCase();
    return isWeiXin.match(/MicroMessenger/i) == "micromessenger";
    },
    loseFocus() {
    const u = navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //判断时候是ios端
    if (this.isWeiXin() && !!u) {
    let currentPosition, timer;
    let speed = 0; // 页面滚动距离
    timer = setInterval(function () {
    currentPosition =
    document.documentElement.scrollTop || document.body.scrollTop;
    currentPosition -= speed;
    window.scrollTo(0, currentPosition); // 页面向上滚动
    currentPosition += speed; // speed变量
    window.scrollTo(0, currentPosition); // 页面向下滚动
    clearInterval(timer);
    }, 1);
    }
    },

     

posted @ 2020-07-25 12:53  Mmlzi  阅读(589)  评论(0)    收藏  举报