美文网首页
移动端监听软键盘弹起事件

移动端监听软键盘弹起事件

作者: 时间de歌 | 来源:发表于2017-09-26 22:07 被阅读54次

使用zepto.min.js(v1.1.4)

$(window).resize(function () {
  $('.fixed-footer').toggleClass('isHide');
})

在华为荣耀9里面软键盘的弹起和消失会触发3次resize();
改进版本:

var clientHeight = $(window).height();
$(window).resize(function(){
    var   height = $(this).height();
    if (height < clientHeight) {  
          $('.fixed-footer').addClass('isHide');      
    } else {
          $('.fixed-footer').removeClass('isHide');      
    }
})

注意:在body上监听不到resize事件。

相关文章

网友评论

      本文标题:移动端监听软键盘弹起事件

      本文链接:https://www.haomeiwen.com/subject/bguosxtx.html