在ios中软键盘弹起时,仅会引起 $('body').scrollTop 值改变,但是我们可以通过输入框的获取焦点情况来做判断,但也只能在ios中采用这个方案,因为在android中存在主动收起键盘后,但输入框并没有失焦,而ios中键盘收起后就会失焦;在android中软键盘弹起或收起时,会改变window的高度,因此监听window的 onresize 事件;
一、Android端监听
let originalHeight
= document
.documentElement
.clientHeight
|| document
.body
.clientHeight
window
.οnresize = function() {
let resizeHeight
= document
.documentElement
.clientHeight
|| document
.body
.clientHeight
if (resizeHeight
< originalHeight
) {
} else {
}
}
二、IOS端监听
if (isIos
) {
document
.body
.addEventListener('focusin', () => {
})
document
.body
.addEventListener('focusout', () => {
})
}
转载请注明原文地址: https://mac.8miu.com/read-507558.html