h5底部輸入框被鍵盤遮擋問題
阿新 • • 發佈:2021-06-28
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