質問:ページの上部からソフトキーボードを元の位置に跳ねていないため、入力フォーカスのうちに、テスト用のiOSマイクロチャンネル端子ブラウザを発見し、彼らが再開する前に、手動でページをスワイプする必要があります。アンドロイドのクライアントは、この問題を見つけることができなかった
解決策を:ときの損失コークスの後に、ページが自動的に元の位置にスクロールします
jQueryのでは
$('input,textarea').on('blur', function() {
var ua = navigator.userAgent.toLowerCase();
if(/micromessenger/.test(ua)) {
if(/iphone|ipad|ipod/.test(ua)) {
var currentPosition, timer;
var speed = 1;
timer = setInterval(function() {
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition-=speed;
window.scrollTo(0,currentPosition);
currentPosition+=speed;
window.scrollTo(0,currentPosition);
clearInterval(timer);
}, 1);
}
}
});
Vue.jsで
Vue.directive('iosbugscroll', {
inserted: function(el, binding, vnode) {
var ua = navigator.userAgent.toLowerCase();
if(/micromessenger/.test(ua)) {
if(/iphone|ipad|ipod/.test(ua)) {
// input、textarea被组件包装的场景
const childInput = el.getElementsByTagName('input');
const childTextarea = el.getElementsByTagName('textarea');
for (let i = 0; i < childInput.length; i++) {
childInput[i].onblur = function temporaryRepair() {
setTimeout(function() {
checkWxScroll();
}, 200);
};
}
for (let i = 0; i < childTextarea.length; i++) {
childSelect[i].onblur = function temporaryRepair() {
setTimeout(function() {
checkWxScroll();
}, 200);
};
}
// input、textarea中的场景
el.onblur = function temporaryRepair() {
setTimeout(function() {
checkWxScroll();
}, 200);
};
}
}
}
});
function checkWxScroll() {
var currentPosition, timer;
var speed = 1;
timer = setInterval(function() {
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition-=speed;
window.scrollTo(0,currentPosition);
currentPosition+=speed;
window.scrollTo(0,currentPosition);
clearInterval(timer);
}, 1);
}
場合に使用します
<input type="text" v-iosbugscroll />