如何确定是否resize事件是由软键盘在手机浏览器引发的? [英] How to determine if a resize event was triggered by soft keyboard in mobile browser?
问题描述
有很多关于软键盘的讨论,但我还没有找到我的问题一个很好的解决方案呢。
There's a lot of discussion about the soft keyboard but I haven't found a good solution for my problem yet.
我有一个调整大小功能,如:
I have a resize function like:
$(window).resize(function() {
///do stuff
});
我想做的事情在该功能的'东西'上所有的调整大小除非它是通过软键盘触发事件。我怎样才能确定是否软键盘触发了调整大小?
I want to do the 'stuff' in that function on all resize events except for when it is triggered by the soft keyboard. How can I determine if the soft keyboard has triggered the resize?
推荐答案
我最近碰到一个需要这个检查的一些问题。我设法解决它,像这样:
I recently ran into some problems that needed a check for this. I managed to solve it like so:
$(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
}
}
我只需要它的文本输入框,但显然这可以为任何一种元素可能触发软键盘/数字选择器等扩展
I only needed it for text inputs, but obviously this could be expanded for any kind of element which might trigger the soft keyboard/number picker etc.
这篇关于如何确定是否resize事件是由软键盘在手机浏览器引发的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!