这个问题是WebApp的通病,特别是用了BootStrap的底部导航栏,又用了input选中时自动移到合适位置,避免软键盘覆盖的时候,会特别明显。

网上有不少分享,都是通过js来实现的,因为我是在安卓手机端,试了多个不管用。

比方说这个:

var oHeight = $(document).height(); //浏览器当前的高度

$(window).resize(function(){//ios软键盘弹出不会触发resize事件

if($(document).height() < oHeight){

$("#footer").css("position","static"); }else{

$("#footer").css("position","absolute"); //adsolute或fixed,看你布局

} });

还有这个:

$("body").find("input[type=text]").each(function() {

$(this).bind('focus', function() {

$('#footer').css('display', 'none');

}).bind('blur', function() {

$('#footer').css({

'position': 'fixed',

'bottom': '0'

});

var footer = $('#footer');

var display = footer.css('display');

if (display == 'none') {

footer.show();

} else {

footer.hide();

}

});

});

最终,我把输入框软键盘防覆盖和底部导航软键盘防顶结合在一起,安卓端用起来还不错。

$(function () {

$('input,textarea').on('focus', function () {

//立即隐藏

$('.footer').css('display', 'none');

var target = this;

setTimeout(function () {

target.scrollIntoViewIfNeeded();

//target.scrollIntoView(true);

//console.log('scrollIntoViewIfNeeded');

}, 200);

});

$('input,textarea').on('click', function () {

var target = this;

setTimeout(function () {

target.scrollIntoViewIfNeeded();

//target.scrollIntoView(true);

//console.log('scrollIntoViewIfNeeded');

}, 200);

});

$('input,textarea').on('blur', function () {

$('.footer').css({

'position': 'fixed',

'bottom': '0'

});

var footer = $('.footer');

var display = footer.css('display');

if (display === 'none') {

footer.fadeIn(2000, function () {//fade

footer.show();

});

//setTimeout(function () {

// footer.show();

//}, 200);

} else {

footer.hide();

}

});

});

bbc018fd8195ab3785c1e25174624271.gif

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐