Measure the height of keyboard on PhoneGap app using jQuery


 I have been working on a PhoneGap project where I wanted  to scroll the content up and down whenever keyboard  appears and disappears.

 After a bit of searching here and there, I found out that  whenever keyboard appears window's resize event if fired.

 So to determine height of keyboard do the following steps

 1. Inside device ready event store original window height  inside a window variable

 window.height = $(window).height();


2. Now on window resize event execute a callback function

 $(window).resize(function(){
    window.currentHeight = $(this).height();
    window.heightDiff = window.height - window.currentHeight;
 });


So whenever there is focus on an input element, window's resize event will be triggered which will execute above function and we will have the height of keyboard inside window.heightDiff variable.

Putting it all together
 function onDeviceReady() {
   window.height = $(window).height();
   $(window).resize(function(){
    window.currentHeight = $(this).height();
    window.heightDiff = window.height - window.currentHeight;
  });
 }

Comments

Anonymous said…
thank u blogger
DataSlexIndia said…
Great post, your all points fully clarify These steps are helpful for Thank you for providing such a valuable information. Visit Us More Info Graphic Designing Services
Enfortra Inc said…
Nice info, I am very thankful to you for sharing this important knowledge. This information is helpful for everyone. So please always share this kind of information. Thanks. Read more info about white label credit reports

Popular posts from this blog

How to get local time from UTC using Moment.JS

Step by step Cordova calabash-ios automation