javascript - Cordova android - 键盘覆盖输入字段
问题描述
我知道这已被问过很多次,但没有一个回答提供解决方案。
<preference name="fullscreen" value="false" />
这不是一个真正的修复,因为我希望应用程序是全屏的。
配置文件选项似乎没有做任何事情。我努力了:
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustResize|stateHidden"
滚动偏移也不起作用,因为没有滚动空间。
$('.myinput').focus(function(e) {
var container = $('.container'),
scrollTo = $('.myinput');
setTimeout((function() {
container.animate({
scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()
});
}), 500);
});
解决方案
请安装:
cordova plugin add ionic-plugin-keyboard --save
然后让cordova准备在你的www文件夹中加载这个新插件。
document.addEventListener('deviceready', function(e){
window.addEventListener('native.keyboardshow', function () {
cordova.plugins.Keyboard.disableScroll(true);
});
});
或者你可以试试这个javascript函数
<script>
setInterval(function(){
if( document.body.className.match('keyboard-open') ) {
document.getElementById("messagearea").style.marginBottom="100px";
}
else{
document.getElementById("messagearea").style.marginBottom="0px";
}
}, 1000);
</script>
推荐阅读
- java - 当java中的值重复时清理对象
- javascript - 有没有办法在 iOS 上的 Safari 中禁用向后滑动动画?
- ios - 如何在 Swift 的类中创建 Getter 或 Setter 属性
- python - 同时重新编码多个变量
- flutter - 如何在颤动中使用 BLoC 模式添加回调?
- javascript - 推特意图分享日文文本在 IE11 中不起作用
- c# - 使用 MonoGame 的内容管理器加载 XML 时出错
- javascript - 如何通过文件加载器将图像加载为多个页面的背景图像
- javascript - 用围绕该单词的 span 标签替换所有出现的单词。不区分大小写
- reactjs - 如何在 React 点击按钮时发出 API 请求