我正在尝试将人们添加到移动设备主页上时,将其网站设置为应用程序打开,但是当我输入字段时,它无法按预期工作。当键盘显示时,它停留在内容上方,不会调整大小。仅当通过手机主屏幕上的快捷方式使用时才会发生这种情况。
这是我的manifest.json:
{
"author": "My Name",
"background_color": "#ffffff",
"description": "App",
"display": "fullscreen",
"icons": [
{
"src": "https://192.168.26.183:8080/img/web-app.png",
"sizes": "192x192",
"type": "image/png"
}
],
"manifest_version": 2,
"name": "App",
"orientation": "portrait",
"short_name": "App",
"start_url": "https://192.168.26.183:8080/",
"theme_color": "#ffffff",
"version": "0.1"
}
这是我的html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- Ask user to add to home screen -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="manifest" href="manifest.json">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body,
html {
height: 100%;
}
.teste {
height: calc(100% - 10px);
width: 100%;
content: '';
background-color: red;
}
</style>
</head>
<body>
<div class="teste"></div>
<input type="text" id="texteeee">
</body>
</html>
答案 0 :(得分:1)
您需要使用position: absolute;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- Ask user to add to home screen -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="manifest" href="manifest.json">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body,
html {
height: 100%;
}
.wrapper {
position: absolute;
width: 100%;
height: 100%;
overflow: auto;
}
.teste {
height: calc(100% - 20px);
width: 100%;
content: '';
background-color: red;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="teste"></div>
<input type="text" id="texteeee">
</div>
</body>
</html>
答案 1 :(得分:1)
网站经常出现此问题。通常Element.scrollIntoView()会有所帮助。 Element.scrollIntoView()方法将调用该元素的元素滚动到浏览器窗口的可见区域。
您可以将其绑定到输入的onFocus
事件。
<input type="text" id="testee" onfocus="getElementById('testee').scrollIntoView()" />