h5处理弹出键盘覆盖输入框问题

监听resize事件,计算位置并滚动页面到一定距离

window.onresize = function(){
			    // 计算输入框离窗口顶部的距离
			    let toTop = document.activeElement.getBoundingClientRect().top;
			    // 滚动页面 使输入框距离顶部100px
			    window.scrollTo({
			        top: document.documentElement.scrollTop + (toTop - 100),
			        behavior: "smooth"
			    });
			}

  

posted @ 2021-02-20 14:05  鸡腿太小  阅读(360)  评论(0编辑  收藏  举报