您似乎遇到了 Safari 浏览器的问题,即打开键盘时页面会滚动到内容之外。为了解决这个问题,您可以尝试实现一个 JavaScript 解决方案来防止这种滚动行为。
试试这个,如果有帮助请告诉我
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prevent Scroll on Keyboard Open</title>
<style>
body {
max-height: 100vh;
overflow: hidden;
}
</style>
</head>
<body>
<div>
<!-- Your content here -->
<input type="text" placeholder="Input field">
</div>
<script>
let initialWindowHeight = window.innerHeight;
let initialBodyMaxHeight;
window.addEventListener('resize', function () {
if (window.innerHeight < initialWindowHeight) {
initialBodyMaxHeight = document.body.style.maxHeight;
document.body.style.maxHeight = window.innerHeight + 'px';
} else {
document.body.style.maxHeight = initialBodyMaxHeight;
}
});
</script>
</body>
</html>
你能提供一个链接让我们检查一下吗?看起来你的容器可能有一个 margin bottom 属性。