h5底部输入框被键盘遮挡问题

winResize() 
function winResize() {
    // var oHeight=$(window).height();
    $(window).resize(function () {          //当浏览器大小变化时
        var // newHeight = $(window).height(),//窗口当前高度
            domNeedTop=90,//(oHeight-newHeight)/2,//40,//当前dom需要距离可视区域 顶部 高度
            domOffsetTop=$("input:focus").offset().top,//当前元素距离顶部高度;
            needScroll=domOffsetTop-domNeedTop;//滚动条需要向上滚动的距离
        $('html , body').animate({scrollTop: needScroll},'slow');
    });
}

var getHeight = $(document).height();

$(window).resize(function(){
 if($(document).height() < getHeight) {
  $('#footer').css('position','static');
 }else {
  $('#footer').css('position','absolute');
 }
});

 

 

 

 

 当键盘弹出时,键盘高度 = 不可见窗口高度

可视区域的中心位置 = 键盘高度 + (窗口高 - 键盘高度)/2
应滚动距离 = 可视区域的中心位置 - 光标offsetTop - (光标被遮挡 ?键盘高度 :0)

 

https://www.cnblogs.com/guolao/p/11936709.html

 

posted @ 2021-06-28 17:00  6NULL9  阅读(727)  评论(0编辑  收藏  举报