ios中,键盘的弹起,页面会往上挪动,使输入框展示在页面中间,键盘隐藏页面会下挪恢复原状
在6.7.4版本中,不会回挪,这将导致有相对定位(fixed,absolute:相对于浏览器窗体)的节点发生位移,导致节点点击事件偏移而无法选中
解决方案:输入框失去焦点(即键盘隐藏时),手动调整页面,
document.activeElement.scrollIntoViewIfNeeded(true)
在每个输入框失去焦点时,响应以下事件即可
在页面插入下面代码就可以了:
<script>
var u = navigator.userAgent, app = navigator.appVersion
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
$(document).ready(function(){
$("input").blur(function(){
if (isIOS) {
blurAdjust()
// alert("1231321233")
}
});
});
// 解决苹果不回弹页面
function blurAdjust(e){
setTimeout(()=>{
// alert("1231321233")
if(document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA'){
return
}
let result = 'pc';
if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS
result = 'ios'
}else if(/(Android)/i.test(navigator.userAgent)) { //判断Android
result = 'android'
}
if( result = 'ios' ){
document.activeElement.scrollIntoViewIfNeeded(true);
}
},100)
}
</script>