侧边栏壁纸
博主头像
lai博主等级

  • 累计撰写 30 篇文章
  • 累计创建 15 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

H5移动端软键盘弹窗导致布局顶起

lai
lai
2022-04-15 / 0 评论 / 0 点赞 / 762 阅读 / 2,166 字
温馨提示:
本文最后更新于 2022-04-15,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

在H5移动端布局时,会采用absolute设置底部固定位置元素,在用户点击输入框,弹出软键盘时,元素会被键盘顶起,导致布局的问题,严重情况会遮挡到输入框等,可以通过监听页面变化缩小时先隐藏底部元素,页面恢复时显示底部元素

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>Document</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/mui/3.7.1/css/mui.min.css" rel="stylesheet">

</head>
<style type="text/css">
.ui-page-login, body {
	width: 100%;
	height: 100%;
	margin: 0px;
	padding: 0px;
}

.mui-content {
	height: 100%;
}

.area {
	margin: 20px auto 0px auto;
}

.mui-input-group {
	margin-top: 10px;
}

.mui-input-group:first-child {
	margin-top: 20px;
}

.mui-content-padded {
	margin-top: 25px;
}

.mui-btn {
	padding: 10px;
}

.link-area {
	display: block;
	margin-top: 25px;
	text-align: center;
}

.spliter {
	color: #bbb;
	padding: 0px 8px;
}

.oauth-area {
	position: absolute;
	bottom: 25px;
	left: 0px;
	text-align: center;
	width: 100%;
	padding: 0px;
	margin: 0px;
}

.oauth-area .oauth-btn {
	display: inline-block;
	width: 50px;
	height: 50px;
	background-size: 30px 30px;
	background-position: center center;
	background-repeat: no-repeat;
	margin: 0px 20px;
	/*-webkit-filter: grayscale(100%); */
	border: solid 1px #ddd;
	border-radius: 25px;
}

.oauth-area .oauth-btn:active {
	border: solid 1px #aaa;
}

.oauth-area .oauth-btn.disabled {
	background-color: #ddd;
}


.mui-input-row {
}
.mui-input-row input{
	border: none;
    border-bottom: 2px solid #a95252;
    background-color: transparent;
}
</style>
<body>
	<div class="mui-content" >
		<div class="mui-content-padded" style="margin-top: 0px;">
			<h2 style="padding: 3.6rem 0rem 4.2rem 0rem; margin-top: 0px;">查询</h2>
			<div class="mui-input-row">
				<input  type="text" class="mui-input-clear mui-input"
					placeholder="单号">
			</div>
			<div class="mui-input-row">
				<input type="text" class="mui-input-clear mui-input"
					placeholder="姓名">
			</div>
		</div>

		<div class="mui-content-padded">

			<div class="mui-button-row">
				<button type="button" id="clearBtn" class="mui-btn mui-btn-danger">重置</button>
				<button type="button" id="submitBtn" class="mui-btn mui-btn-primary">提交</button>
			</div>
		</div>
	</div>
	<div class="mui-content-padded oauth-area">
		<h5>中底部元素 © 2022-2025</h5>
	</div>


<script src="https://cdn.bootcdn.net/ajax/libs/mui/3.7.1/js/mui.min.js"></script>
</body>
</html>

关键js

(function($, doc) {
	$.init({});
	$.plusReady(function() {});

	$.ready(function() {
	var originalHeight = document.documentElement.clientHeight || document.body.clientHeight;

	window.onresize = function() {

			//软键盘弹起与隐藏  都会引起窗口的高度发生变化
			var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;

			if(resizeHeight * 1 < originalHeight * 1) { //resizeHeight<originalHeight证明窗口被挤压了
					mui('.mui-content-padded.oauth-area')[0].style.display = "none"
			} else {
					mui('.mui-content-padded.oauth-area')[0].style.display = "block"
			}
	}
});

}(mui, document));		

参考文章

mui在调起软键盘时,底部内容被推起的解决办法

VUE H5文本框获取焦点唤起键盘时,绝对定位的元素被键盘顶上去的问题解决方案

0

评论区