如何使用phonegap防止键盘在iOS应用程序中向上推网页视图 [英] How to prevent keyboard push up webview at iOS app using phonegap

查看:30
本文介绍了如何使用phonegap防止键盘在iOS应用程序中向上推网页视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当屏幕底部的输入字段获得焦点时,键盘将我的 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.

我想防止键盘向上推网页视图.

I want to prevent the keyboard pushing up the webview.

有人有想法吗?

推荐答案

On focus, set 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应用程序中向上推网页视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆