1***@qq.com
1***@qq.com
  • 发布:2023-12-12 12:10
  • 更新:2023-12-12 12:10
  • 阅读:72

解决安卓弹出虚拟键盘时,顶部fixed消失的问题

分类:uni-app

思路:关掉输入框的adjust-position,键盘就不会把fixed元素顶上去。然后弹出键盘时页面滚动到输入框光标的位置。

<input :adjust-position="false" @keyboardheightchange="handleKeyboardHeightChange"></input>
handleKeyboardHeightChange(e) {  
    const keyboardHeight = e.detail.height  
    // e.target.offsetTop就是输入框中的光标在整个页面的scrollTop。  
    const inputTop = e.target.offsetTop  
    if (keyboardHeight > 0) {  
        const safeHeight = uni.getWindowInfo().safeArea.height  
        const upperHeight = safeHeight - keyboardHeight  

        this.pagePaddingBottom = keyboardHeight  
        setTimeout(() => {  
            uni.pageScrollTo({  
                scrollTop: inputTop - upperHeight + 50,  
                duration: 50,  
            })  
        })  
    } else {  
        this.pagePaddingBottom = 0  
    }  
}
0 关注 分享

要回复文章请先登录注册