I have a PHP web application with simple css. When i run that application on Android tablets, and try to login, soft touch keyboard pops up and hiding my text input fields. I have tried searching on stack overflow for similar issues but all questions are related to asp.net. nothing specifically mentioned about other languages. I have tried putting foloowing solution but didnt work:
//added this on document.ready function
if(navigator.userAgent.indexOf('Android') > -1){
$('html').css({ "overflow": "auto !important" });
$('body').css({ "height": "auto !important" });
$('body').css({ "overflow": "auto !important" });
$('.scrollable').css({ "position": "inherit !important" });
$('body').on('focusin', 'input, textarea', function(event) {
//alert("test");
var scroll = $(this).offset();
window.scrollTo(0, scroll);
});
}
or
//added in css file
html {
overflow: auto;
}
body {
height:auto;
overflow: auto;
}
.scrollable {
position:inherit;
}
Please help.
Thanks
I prepared a fiddle for you, maybe you can use it: https://jsfiddle.net/fe82uhrp/1/
JS:
/***** using jQuery *****/
$('input').focus( function() {
var $input = $(this);
$input.css('background', 'yellow');
var scroll = $input.offset();
$input.closest('#viewport').animate({
scrollTop: $input.offset().top
}, 'slow');
});
/***** using plain JS *****/
var viewport = document.getElementById('viewport');
var allInputs = document.getElementsByTagName('input');
for( var i=0; i<allInputs.length; i++) {
var item = allInputs[i];
console.log('set focus event handler on', item)
item.onfocus = function() {
this.style.background = "yellow";
item.scrollIntoView();
}
};
I wouldn't use scrolling the window itself, but a page wrapping container (#viewport in my example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With