親測 ios 9 ,ios10 系統有效,其他請自行測試,建議通過判斷系統類型來動態引入此腳本
var isIPHONE = navigator.userAgent.toUpperCase().indexOf("IPHONE")!= -1;if(isIPHONE){ // 元素失去焦點隱藏iphone的軟鍵盤 function objBlur(obj,time){ var startTime=0,endTime=0, time = !time?30:time, docTouchend = function(event){ endTime = new Date().getTime(); if(event.target!= obj && (endTime - startTime <300)){ setTimeout(function(){ obj.blur(); document.removeEventListener("touchend", docTouchend,false); },time); } }; document.addEventListener("touchstart",function(){ startTime = new Date().getTime(); }); document.addEventListener("touchend", docTouchend,false); } $("input").on("focus",function(){ var id = this.id; var self = this; var H = window.innerHeight; var pos = getPosition(self); if(isIPHONE){ var input = new objBlur(self); input=null; } }); function getPosition(target) { var left = 0, top = 0; do { left += target.offsetLeft || 0; top += target.offsetTop || 0; target = target.offsetParent; } while(target); return { left: left, top: top }; }}
以上這篇解決移動端 ios 系統鍵盤遮擋的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答