JS判断软键盘弹起,移动端

移动端软键盘弹起监听:

function fn_isShowKeyboard (cb)  {
    const winHeight = window.innerHeight;
    window.onresize = function() {
        var thisHeight = window.innerHeight;
        if (winHeight - thisHeight > 50) {
            //当软键盘弹出,在这里面操作
            cb(true)
        } else {
            //当软键盘收起,在此处操作
            cb(false)
        }
    }
}
展示评论