Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • 固定定位键盘弹起挡住输入框内容

固定定位键盘弹起挡住输入框内容

12.固定定位布局键盘挡住输入框内容?

<div class="submit">
     <button type="button" class="btn">提交信息</button>
</div>

.submit {
    display: flex;
    width: 100%;
    justify-content: center;
    position: fixed;
    bottom: 0;
}

通过resize函数监听窗口变化,然后把fixed属性改为static即可解决

var windheight = $(window).height();  /*未唤起键盘时当前窗口高度*/

$(window).resize(function(){
   var docheight = $(window).height();  /*唤起键盘时当前窗口高度*/        
   if(docheight < windheight){            /*当唤起键盘高度小于未唤起键盘高度时执行*/
      $(".submit").css("position","static");
   }else{
      $(".submit").css("position","fixed");
   }           
});

Edit this page
最近更新: 2025/12/2 01:46
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人