首页 > 移动平台 > 详细

解决absolute fixed元素在安卓唤起虚拟键盘时,元素被挤上来。

时间:2019-09-30 09:57:48      阅读:150      评论:0      收藏:0      [点我收藏+]
//由于安卓虚拟键盘也会占位置,致使页面高度变小,所以absolute fixed元素跟着移动
//防止唤起键盘,导致absolute元素被挤上来
var isAndroid = navigator.userAgent.indexOf(‘Android‘) > -1 || navigator.userAgent.indexOf(‘Adr‘) > -1;
if (isAndroid){//如果是安卓手机的浏览器
    var win_h = $(window).height();//关键代码
    $("body").height(win_h);//关键代码
    window.addEventListener(‘resize‘, function () {
        // Document 对象的activeElement 属性返回文档中当前获得焦点的元素。
        if (document.activeElement.tagName === ‘INPUT‘ || document.activeElement.tagName === ‘TEXTAREA‘) {
          if($(‘.footerText‘).is(‘:visible‘)){
            $(‘.footerText‘).hide();
          }else{
            $(‘.footerText‘).show();
          }
        }
    });
}

解决absolute fixed元素在安卓唤起虚拟键盘时,元素被挤上来。

原文:https://www.cnblogs.com/wugai/p/11610907.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!