有一种已知技术可以在模式窗口打开时禁用页面滚动。
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 上检查的全屏 url
只需在 iPhone 或带有 IOS 12+ 的 XCode 中打开尝试滚动,然后专注于输入并再次尝试滚动。
原文由 Dzmitry Vasilevsky 发布,翻译遵循 CC BY-SA 4.0 许可协议
刚刚进行了繁琐的搜索,正如您在以下文章中指出的那样,这似乎是 iPhone 的一个问题: https ://blog.opendigerati.com/the-eccentric-ways-of-ios-safari-with-the-keyboard-b5aa3f34228d
所以你无法肯定地使用 css 来做到这一点。
但这并不能阻止您使用 JQuery 和 Javascript >:)
这是针对您的场景的不整洁的解决方法。也 只在 iPhone 上 测试过多个文本框:
简而言之,解释一下我做了什么。
假如说,
注意:我使用 JQuery 来简化事情。如果你想使用纯javascript,你可以找到特定代码的替代品。