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

  • Post author:
  • Post category:其他


//由于安卓虚拟键盘也会占位置,致使页面高度变小,所以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();
}
}
});
}

转载于:https://www.cnblogs.com/wugai/p/11610907.html