解决弹框滚动穿透和ios输入框错位

1,407 阅读1分钟

简单粗暴的解决方式

移动端当有 fixed 遮罩背景和弹出层时,在屏幕上滑动能够滑动背景下面的内容,同时存在IOS 11系统下弹框内输入框错位问题,下面方案是为解决这两个问题

//显示弹框时:
	scrollTop = document.scrollingElement.scrollTop;
    document.body.style.cssText = "position: fixed; width: 100%;"
    document.body.style.top = -scrollTop + 'px';		// 使页面处于原位置


// 隐藏弹框时:
	document.body.style.cssText = ""
	document.scrollingElement.scrollTop = scrollTop;