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

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与数据库进行交互
相关内容
批量提取word文档标题
Zend推出新开发套件 PHP...
Vue项目Element-UI表格el...
如何删除电脑中超大文件
如何搜索到自己想要的资源
3个DeepSeek隐藏玩法,99...
如何访问有密码的电脑
支持上百个网站的漫画下...
-
HTML粘性滑块导航页面Demo - 可自由填充内容
2025-04-07 1098
-
很上档次别具一格的代码注释方式
2025-04-07 1213
-
下载B站视频,知道这些方法就够了
2025-03-10 1403
-
去美国必备口语推荐
2025-03-03 1144
-
DeepSeek小白使用指南,99% 的人都不知道的使用技巧
2025-04-30 1063
-
数据缓存Memcached与Redis的区别和选择
2021-07-14 870
-
DeepSeek最强使用攻略,放弃复杂提示词,直接提问效果反而更好?
2025-04-30 1286
-
Deepseek 高效使用指南,1分钟学会
2025-04-30 1206
-
手机相机功能不会用看过来
2025-07-27 1182
-
正则表达式语法规则
2025-01-08 1527
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


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