input获取焦点页面自动滚动

微信下测试无问题

/*监听input状态,屏幕滚动到input,上下居中
 *在安卓手机上屏幕尺寸变化会产生resize事件。所以监听resize事件。
 *然后定位到input框。
 */
window.addEventListener('resize', function () {
    if(document.activeElement.tagName === 'INPUT'){
        document.activeElement.scrollIntoView({behavior: "smooth"})
    }
 })

猜你喜欢

转载自blog.csdn.net/wzzehui/article/details/81170137