手机端软键盘弹出挤压页面的问题

解决这个问题的基本思路是:

1、怎样监听软键盘弹起这个事件

2、监听到这个事件后怎样操作才能让页面不被挤压

一、解决在手机页面App中手机软键盘弹出软键盘挤压页面问题

复制代码
var originalHeight=document.documentElement.clientHeight || document.body.clientHeight;
    window.onresize=function(){
        var  resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
        //软键盘弹起与隐藏  都会引起窗口的高度发生变化
        if(resizeHeight*1<originalHeight*1&&isfocus==true){ //resizeHeight<originalHeight证明窗口被挤压了
           plus.webview.currentWebview().setStyle({
                height:originalHeight
           });
        }
    } 
复制代码
plus.webview.currentWebview().setStyle({
  softinputMode: "adjustResize"  // 弹出软键盘时自动改变webview的高度
});

二、解决在浏览器中打开网页软键盘挤压页面问题

复制代码
//获取原始窗口的高度
var isfocus=false;
var originalHeight=document.documentElement.clientHeight || document.body.clientHeight;
window.onresize=function(){
    var  resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
    //软键盘弹起与隐藏  都会引起窗口的高度发生变化
    if(resizeHeight*1<originalHeight*1&&isfocus==true){ //resizeHeight<originalHeight证明窗口被挤压了
    $('.hideBtn').css('display','none');
    }else{
        $('.hideBtn').css('display','block'); 
    }
} 
$("input").focus(function(){
    isfocus=true;
     
});
$("input").blur(function(){
    isfocus=false;
})
复制代码

 

posted on   明启心动  阅读(2760)  评论(2编辑  收藏  举报

努力加载评论中...
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示