var winHeight = $(window).height();
var u = navigator.userAgent,app = navigator.appVersion
var isIOS = !!u.match(/\(i[^;]+;( U;)? cpu.+Mac OS X/); //ios终端
var adOrIosTime = 0;
$("input").blur(function(){
clearTimeout(adOrIosTime);
if (isIOS) {
adOrIosTime = setTimeout(()=>{
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)
}else{
adOrIosTime = setTimeout(()=>{
window.scrollTo(0,Math.max(winHeight - 1,0));
},100);
}
});
注意:************************有时会出现绑定事件不成功*****************可以这样写**************************
<input type=‘text‘ onblur="inputBlur();"/>
<script type="text/JavaScript">
var winHeight = $(window).height();
var u = navigator.userAgent,app = navigator.appVersion
var isIOS = !!u.match(/\(i[^;]+;( U;)? cpu.+Mac OS X/); //ios终端
var adOrIosTime = 0;
function inputBlur(){
clearTimeout(adOrIosTime);
if (isIOS) {
adOrIosTime = setTimeout(()=>{
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)
}else{
adOrIosTime = setTimeout(()=>{
window.scrollTo(0,0));
},100);
}
}
</script>
总结以上是内存溢出为你收集整理的解决IOS端(h5页面)input确定后,页面不恢复的问题,超好用全部内容,希望文章能够帮你解决解决IOS端(h5页面)input确定后,页面不恢复的问题,超好用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)