思路:关掉输入框的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 个评论
要回复文章请先登录或注册