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中即可

posted @ 2021-03-10 13:39  TheYouth  阅读(148)  评论(0编辑  收藏  举报