首页 > 教程
H5页面移动端软键盘弹出时,底部absolute或者fixed定位被顶上去
- 2024-03-02
- 1831 ℃

H5开发中,移动端页面的底部菜单栏,通常会使用fixed或者absolute定位在底部,特别是登录,注册页面底部的信息,在安卓手机上经常会出现软键盘弹出时,底部定位被顶上去,下面提供vue和jQuery两种解决办法。
vue解决方法
<!--html部分-->
<div class="footer" v-show="hideshow"></div>
// js 部分
data(){
return {
docmHeight: document.documentElement.clientHeight, //默认屏幕高度
showHeight: document.documentElement.clientHeight, //实时屏幕高度
hideshow:true, //显示或者隐藏footer
}},mounted() {
// window.onresize监听页面高度的变化
window.onresize = ()=>{
return(()=>{
this.showHeight = document.body.clientHeight;
})()
}},//监听watch:{
showHeight:function() {
if(this.docmHeight > this.showHeight){
this.hideshow=false
}else{
this.hideshow=true
}
}
}js解决方案
var winHeight = $(window).height(); //获取当前页面高度
$(window).resize(function () {
var thisHeight = $(this).height();
if ( winHeight - thisHeight > 140 ) {
//键盘弹出
$('.footer').css('position','static');
} else {
//键盘收起
$('.footer').css({'position':'fixed','bottom':'0'});
}
})上一篇:微信的8个实用功能,隐藏技巧
下一篇:如何使用php与数据库进行交互
相关内容
进化式产品创新
怎样在淘宝买东西最便宜
mysql数据库优化
JS正则常用校验大全
可免费使用的网站CDN加速服务
微信公众号推送模板消息
Duplicate Cleaner Pro...
为什么你家装的千兆网还...
-
微信转账查看对方是否把我删除好友
2025-06-22 1940
-
微信快速把图片变成表格
2025-06-22 1421
-
鼠标拖拽移动DIV
2025-04-07 1190
-
解析PHP中的extract()函数
2021-05-10 1690
-
iOS 可用的可换源小说阅读器
2025-04-27 2040
-
如何删除电脑中超大文件
2021-10-27 685
-
php提高性能的几个小技巧
2021-04-13 856
-
mac 80个使用技巧合集
2025-08-24 1318
-
PHP超级Ping API接口 源码
2025-04-07 1333
-
简单实用的电脑技巧,提高您的工作效率!
2021-10-27 999
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


进入有缘空间
点击分享文章