js如何获取键盘高度

在移动端或混合app开发中,js如何获取键盘高度,直接贴上代码吧

input是一个html input 标签

 1 var timer = {
 2     id:null,
 3     run:function (callback,time) {
 4         this.id = window.setInterval(callback,time);
 5     },
 6     clean:function () {
 7         var that = this;
 8         this.id = window.clearInterval(that.id);
 9     }
10 };
11 var keyboardHeight = 0,screenHeight = window.innerHeight;
12 input.addEventListener('focus',function (evt) {
13     if(!keyboardHeight){
14         timer.run(function () {
15             if (screenHeight !== window.innerHeight) {
16                 keyboardHeight = screenHeight-window.innerHeight;
17                 timer.clean()
18             }
19         }, 50)
20     }
21 });
22 input.focus();

 

posted @ 2018-08-22 16:57  JoVee  阅读(11429)  评论(0编辑  收藏  举报