1、問題表現:H5開發,下單頁面,下圖所示,在ios 12系統的蘋果手機端,在輸入電話號,之類信息,經常點擊去支付沒有任何反應,頁面上下滑動,再點擊,就可以支付
2、原因分析:結合頁面表現,查了網上資料,ios12系統鍵盤迴收後會留下一個透明的遮罩層,在點擊頁面底部,點擊事件沒法穿透遮罩層,相當於事件被攔截了。
3、處理方式,項目用的vue開發的,處理思路:在input失去焦點後,頁面上下滾動1px,去除遮罩層;該方法作用所有input需要在input用@blur=iosBlur引入
iosBlur() {
let ua = window.navigator.userAgent;
//$alert('瀏覽器版本: ' + app + '\n' + '用戶代理: ' + ua);
if (!!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
//ios系統
let currentPosition, timer;
let 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);
// alert("失去焦點")
console.log("失去焦點")
}, 100);
}
}