问题描述
当屏幕底部的输入字段获得焦点时,键盘将我的 webview 向上推,页面的上部不再可见.
When an input field at bottom of the screen has focus, the keyboard pushes up my webview and the upper part of the page is not visible anymore.
我想防止键盘向上推 webview.
I want to prevent the keyboard pushing up the webview.
有人有想法吗?
推荐答案
在焦点上,设置 window.scrollTo(0,0); 这样可以防止键盘完全上推 webview
On focus, set window.scrollTo(0,0); This prevents keyboard from pushing up webview completely
$('input').on('focus', function(e) {
e.preventDefault(); e.stopPropagation();
window.scrollTo(0,0); //the second 0 marks the Y scroll pos. Setting this to i.e. 100 will push the screen up by 100px.
});
如果您不想为 Y 滚动位置设置静态值,请随意使用此 我编写的短插件可以自动在输入字段下方对齐键盘.它并不完美,但它可以完成工作.只需将其称为焦点,如上所示:
If you don't want to set a static value for your Y scroll position, feel free to use this short plugin I've written that automatically aligns the keyboard underneath the input field. It's not perfect, but it does the job. Just call this on focus as shown above:
setKeyboardPos(e.target.id);
这篇关于如何使用 phonegap 在 iOS 应用程序中防止键盘上推 webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)