關於移動端的文本框獲取焦點時致使fixed或absolute定位的按鈕被手機鍵盤頂上去的問題

方法一:瀏覽器

var win_h = $(window).height();//關鍵代碼
window.addEventListener('resize', function () {
    if($(window).height() < win_h){
        $('.share-btn-box').hide();
    }else{
        $('.share-btn-box').show();
    }
});

方法二:ide

//navigator.userAgent.indexOf用來判斷瀏覽器類型
var isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1;
if (isAndroid){//若是是安卓手機的瀏覽器
    var win_h = $(window).height();//關鍵代碼
    $("body").height(win_h);//關鍵代碼
    window.addEventListener('resize', function () {
        // Document 對象的activeElement 屬性返回文檔中當前得到焦點的元素。
        if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') {
          if($('.share-btn-box').is(':visible')){
            $('.share-btn-box').hide();
          }else{
            $('.share-btn-box').show();
          }
        }
    });
}
相關文章
相關標籤/搜索