微信内置浏览器H5 弹出键盘 遮盖文本框解决办法 Fixed失效

时间:2023-03-09 18:39:25
微信内置浏览器H5 弹出键盘 遮盖文本框解决办法 Fixed失效
if(/Android [4-6]/.test(navigator.appVersion)) {
window.addEventListener("resize", function() {
if(document.activeElement.tagName=="INPUT" || document.activeElement.tagName=="TEXTAREA") {
window.setTimeout(function() {
document.activeElement.scrollIntoViewIfNeeded();
},0);
}
})
} //Fixed失效 监听input框事件
        $("input,textarea").blur(function(){
setTimeout(function () {
var scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
},100);
})

有很多页面是动态画出来的,直接用上面的写法是触发不了的,只能委托给document

 container.on("blur","input,textarea",function(){
setTimeout(function () {
var scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
},100);
})

  

  

借鉴于 http://www.cnblogs.com/Miracle-ZLZ/p/10030608.html