手机端上点击input框软键盘出现时把input框不被覆盖,显示在屏幕中间

Posted xzzzys

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手机端上点击input框软键盘出现时把input框不被覆盖,显示在屏幕中间相关的知识,希望对你有一定的参考价值。

 1  
用定位为题来解决
var oHeight = $(document).height(); //浏览器当前的高度
   
   $(window).resize(function(){

        if($(document).height() < oHeight){
         
        $("#footer").css("position","static");
    }else{
         
        $("#footer").css("position","absolute");
    }
        
   });

2 第二种方法是改变可是区域的高度
var loaclHeight = $("section").height();//获取可视宽度
$("input,textarea").focus(function() {
var keyboardHeight = localHeight - $("section").height();//获取键盘的高度
var keyboardY = localHeight - keyboardHeight;
var addBottom = (parseInt($(this).position().top) + parseInt($(this).height()));//文本域的底部
var offset = addBottom - keyboardY;//计算上滑的距离
$("section").scrollTop(offset);
}); 

以上是关于手机端上点击input框软键盘出现时把input框不被覆盖,显示在屏幕中间的主要内容,如果未能解决你的问题,请参考以下文章