H5輸入框調起鍵盤界面彈起和收回設置

h5 解決ios和 Android 輸入框無法擡起和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 (isiOS) { 
         document.body.addEventListener('focusin', () => {        
            setTimeout(()=>{ 
                  document.body.scrollTop=document.body.scrollHeight;   
            },100) 
        }) 
        document.body.addEventListener('focusout', () => { 
           window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) 
        }) 
    } 
    if (/Android/gi.test(navigator.userAgent)) {
        window.addEventListener('resize', function () {
            if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {
                
                window.setTimeout(function () {
                    document.activeElement.scrollIntoView();
                }, 100);
            }
        }.bind(this)) 
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章