在安卓手机上面会出现position:fixed固定定位的问题,当用户点击搜索框的时候,手机的虚拟键盘会把固定在底部的div顶到手机虚拟键盘的正上方,查询后发现是虚拟键盘调用时浏览器高度被压缩了,根据这个特性我们可以通过监听浏览器窗口的高度改变元素的定位或者显示隐藏。
代码如下:

windowInnerHeight = window.innerHeight; //获取当前浏览器窗口高度
$(window).resize(function(){
if(window.innerHeight < windowInnerHeight){
$('.footer').css('position','static');//也可以在css文件夹写个类名,然后相对应的removeClass和addClass既可
}else{
$('.footer').css('position','absolute');
}
});
---------------------
原文:https://blog.csdn.net/xiazeqiang2018/article/details/81319366
---------------------

var windheight =window.innerHeight;         
 var bottomx = document.getElementById('bottomx'); //底部导航
   window.onresize(function(){    var docheight = window.innerHeight;         
    if(docheight < windheight){            
        bottomx.style.position = 'static';
    }else{
        bottomx.style.position = 'fixed';
    }     
   })

  

posted on 2018-12-20 15:25  liuruyi007  阅读(1014)  评论(0)    收藏  举报