【发布时间】:2019-10-14 12:20:09
【问题描述】:
有一种已知的技术可以在打开模式窗口时禁用页面滚动。
CSS:
html {
height: 100%;
}
body.disable-scroll {
position: fixed;
height: 100%;
overflow: hidden;
}
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
</head>
<body class="disable-scroll">
<div class="page-content">
<input type="text">
... content ...
</div>
</body>
</html>
但在 IOS Safari 上,打开虚拟键盘后会启用滚动。它甚至比window.innerHeight + window.scrollX 滚动更多。页面底部出现一些空白。
编者网址
https://codesandbox.io/s/condescending-snow-skuo5?fontsize=14
在 iPhone 上检查的全屏网址
https://skuo5.codesandbox.io/
只需在 iPhone 或 XCode 中打开 IOS 12+ 尝试滚动,然后专注于输入并再次尝试滚动。
【问题讨论】: