Jos*_*ron 33 html javascript browser mobile jquery
关于软键盘的讨论很多,但我还没有找到解决问题的好方法.
我有一个调整大小的功能,如:
$(window).resize(function() {
///do stuff
});
Run Code Online (Sandbox Code Playgroud)
我希望在所有调整大小事件中对该函数执行'stuff',除非它由软键盘触发.如何确定软键盘是否触发了调整大小?
kir*_*kun 17
我最近遇到了一些需要检查的问题.我设法像这样解决它:
$(window).on('resize', function(){
// If the current active element is a text input, we can assume the soft keyboard is visible.
if($(document.activeElement).attr('type') === 'text') {
// Logic for while keyboard is shown
} else {
// Logic for while keyboard is hidden
}
}
Run Code Online (Sandbox Code Playgroud)
我只需要它用于文本输入,但显然可以扩展任何可能触发软键盘/数字选择器等的元素.
我刚刚修复了kirisu_kun的答案,使用prop()而不是attr():
$(window).on('resize', function(){
// If the current active element is a text input, we can assume the soft keyboard is visible.
if($(document.activeElement).prop('type') === 'text') {
// Logic for while keyboard is shown
} else {
// Logic for while keyboard is hidden
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10133 次 |
| 最近记录: |