1. 程式人生 > 其它 >移動端-判斷是否安卓ofios 鍵盤抬起擋住文字框輸入內容

移動端-判斷是否安卓ofios 鍵盤抬起擋住文字框輸入內容

當輸入框獲取游標 鍵盤抬起 輸入框向上對齊頂部(配合vue中的refs使用,給誰設定,誰就跟頂部對齊)

 <input v-model="ownerName" type="text" maxlength="16" placeholder="請輸入申請人姓名 " @focus="userFocus()" autocomplete="off" ref="userobj">

methods: {
        //申請人姓名獲取焦點(防止鍵盤彈起遮住輸入框)
        userFocus(){
               let that=this;
             setTimeout(()
=>{ let pannel=that.$refs.userobj; //讓當前的元素滾動到瀏覽器視窗的可視區域內 pannel.scrollIntoView(true); //此方法是標準的scrollIntoView()方法的專有變體 pannel.scrollIntoViewIfNeeded(); },300) }, }

判斷移動端是安卓of ios

        var
u = navigator.userAgent; var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android終端 var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端 if (isAndroid) { // 安卓機 console.log("安卓手機"); } else if(isiOS){ console.log(
"isiOS"); }

兩個配合可以解決安卓鍵盤抬起 輸入框被擋住的問題(偶爾被擋住,當時這個問題是存在的,這是個卡bug)