zoukankan      html  css  js  c++  java
  • 手机端软键盘弹出挤压页面的问题

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

    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;
    })
  • 相关阅读:
    nginx 中用 sed 批量增加配置文件内容
    apache中 sed 指定文件中某字符串增加行
    centos7 下 nfs 搭建总结
    centos7.2 环境下两个数据库的安装部署
    centos7.2 环境下 mysql-5.1.73 安装配置
    二代云盒混合网
    安装tftp
    云盒所有服务检查
    将某个目录下的 文件(字符窜) 只将数字过滤出来
    让VS2012支持Less css
  • 原文地址:https://www.cnblogs.com/zhaoqiming/p/7997587.html
Copyright © 2011-2022 走看看