我有一个布局需要响应键盘出现。
- 安卓(版本6+) - 当键盘出现时,
window.resize
会触发。 - iOS(版本10+) -
window.resize
不会触发。
我准备了一个小演示,展示了内部高度如何响应键盘的出现。您可以点击输入框来唤起键盘。
// select the paragraph element
const innerHeightParagraph = document.getElementById("inner-height")
// set the innerHeight for the first time.
innerHeightParagraph.innerText = window.innerHeight
// register resize event.
window.addEventListener('resize', function() {
innerHeightParagraph.innerText= window.innerHeight
})
p {
font-size:60px; margin:0px;
}
<h1>Current InnerHeight</h1>
<p id="inner-height"></p>
<input></input>
iOS的推荐解决方法是什么?