【发布时间】:2018-05-30 21:31:36
【问题描述】:
我在使用 Iphone 等 IOS 设备时遇到了问题。当我关注输入(它在固定的 div 内)时,虚拟键盘显示。然而,它也是滚动整个视口和位置固定的 div 滚动。如何解决?
我一直在研究许多帖子和论坛
我想要什么:
位置固定的 div 必须保持在顶部
出现虚拟键盘时防止滚动整个网站
允许在搜索结果 div 上滚动
我的html:
<div class="header">
<button type="button" id="searchButton">Search</button>
<div class="search"><!-- Its not visible until user click on search button -->
<input type="text" id="search" placeholder="Search here"/>
</div>
</div>
这是我的 html,当我输入一些内容时,它会根据我的
关键词。结果将附加到DOM。
<div class="search-result"><!-- Appended via javascript -->
<ul class="suggest-list">
<li>Some item of search result</li>
</ul>
</div>
还有 javascript:
$(document).on("click", "#searchButton", function(e){
var field = $("#search"); // Gets the search input
field.focus(); // Focus the input for virtual keyboard shows up
});
/* cache dom references */
var $body = jQuery('body');
/* bind events */
$(document).on('focus', 'input', function() {
$body.addClass('fix');
})
.on('blur', 'input', function() {
$body.removeClass('fix');
});
还有 sass 文件:
.header {
position: fixed;
height: 50px;
background: #dadce7;
input {
height: 100%;
width: 100%;
border: 0;
}
}
/* Style of search result */
.search-result {
position: fixed;
top: 50px;
bottom: 0;
width: 100%;
overflow-y: scroll;
}
/* Fix the layout */
body {
&.fix {
overflow: hidden;
position: fixed; // overflow will be work;
width: 100%;
height: 100%;
}
}
【问题讨论】:
标签: javascript ios html css virtual