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

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

问题描述

当屏幕底部的输入字段具有焦点时,键盘会向上推动我的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.

推荐答案

在焦点上,设置 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. 
});

如果不想设置静态值滚动位置,随时可以使用此短插件,自动对齐输入字段下的键盘。这不是完美的,但它做的工作。只需调用此焦点如上所示:

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);

这篇关于如何防止键盘上推webview在iOS应用程序使用phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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