input在微信上失去焦點頁面不回彈問題

web頁面在IOS微信上,遇到:當input失去焦點且軟鍵盤收起來的時候,頁面沒有回彈,致使下面空出一個軟鍵盤大小的高度。web

解決方案微信

function isWeiXinAndIos{
    let ua = '' + window.navigator.userAgent.toLowerCase()
    let isWeixin = /MicroMessenger/i.test(ua)
    let isIos = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(ua)
    return isWeixin && isIos
}

function  weChatInputBug(){
    let myFunction
    let isWXAndIos =isWeiXinAndIos();
    if (isWXAndIos) {
      document.body.addEventListener('focusin', () => {
        clearTimeout(myFunction)
      })
      document.body.addEventListener('focusout', () => {
        clearTimeout(myFunction)
        myFunction = setTimeout(function() {
          window.scrollTo({top: 0, left: 0, behavior: 'smooth'})
        }, 200)
      });
    }

  }
相關文章
相關標籤/搜索