web 移动端键盘处理-vue移动端那些事

const originHeight = document.documentElement.clientHeight || document.body.clientHeight window.addEventListener('resize', () => { const resizeHeight = document.documentElement.clientHeight || document.body.clientHeight // android 键盘弹起 if (originHeight > resizeHeight) { // 将元素滚动到可视区域 const activeElement = document.activeElement const tagName = activeElement.tagName if (tagName === 'INPUT' || tagName === 'TEXTAREA') { activeElement.scrollIntoViewIfNeeded() } } }, false)
上面代码写在js文件中,然后引入到main.js中即可

将来的自己,会感谢现在不放弃的自己!
原文地址:https://www.cnblogs.com/TheYouth/p/14511120.html