移动端底部input唤醒手机软键盘遮挡输入框问题

    技术2022-07-16  74

    <input type="text" value="" class="btninput"/> //针对直接在浏览器打开此方法 $('.btninput').bind('focus', function() { // 软键盘弹起之后再调整滚动条位置 if ($(this).offset().top > document.body.scrollHeight / 2) { setTimeout(function () { window.scrollTo(0,document.body.scrollHeight); }, 500); } }); //针对嵌入app页面使用 $('.btninput').focus(function(e){ var u = navigator.userAgent; var Android = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 if(Android){ $('body').height( $('body').height()+300) $('body').scrollTop(300) } }) // 失去焦点时重新回到原来的状态 $('.btninput').blur(function(e){ var u = navigator.userAgent; var Android = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 if(Android){ $('body').height( $('body').height()-300) $('body').scrollTop(0) } })
    Processed: 0.010, SQL: 9