keyboard hide input (position:fixed; bottom:0;) with phonegap on android

自古美人都是妖i 提交于 2020-01-13 14:00:50

问题


Tried a lot of things

<preference name="fullscreen"                 value="false" />  
<preference name="android-windowSoftInputMode"    value="adjustResize" />

This seems to be the prefered methods however my keyboard still show on top of my input.

Should adjustResize force the app window to resize? do I need something else?

How can I stop it from hiding my element in position fixed bottom?

Thanks


回答1:


Try something like this:

Add these piece of code in $(document).ready(function() {}); function in your html page where soft keyboard is appearing.

 var initialScreenSize = window.innerHeight;
 window.addEventListener("resize", function() {
  if(window.innerHeight < initialScreenSize){
     $("#footer").hide();
     document.body.style.position = "fixed";
  }
  else{
     document.body.style.position = "";
     $("#footer").show();                                      
  }
 });

This will might help you.




回答2:


You can detect focused textarea or input then wait a while until keyboard is shown and finally scroll the page to reach focused input. Hope this help you, cheers.

var container = $('body'),
        scrollTo = $('#textarea');

    setTimeout((function() {
        container.animate({
        scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()
        });
    }), 500);


来源:https://stackoverflow.com/questions/20208463/keyboard-hide-input-positionfixed-bottom0-with-phonegap-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!