用户登录
用户注册

分享至

如何使用 phonegap 在 iOS 应用程序中防止键盘上推 webview

  • 作者: 亖呉?盀
  • 来源: 51数据库
  • 2023-02-09

问题描述

当屏幕底部的输入字段获得焦点时,键盘将我的 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);
软件
前端设计
程序设计
Java相关