如何确定移动浏览器中的软键盘是否触发了调整大小事件? [英] How to determine if a resize event was triggered by soft keyboard in mobile browser?

查看:11
本文介绍了如何确定移动浏览器中的软键盘是否触发了调整大小事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多关于软键盘的讨论,但我还没有找到解决我问题的好方法.

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

我想在所有调整大小事件的那个函数中做'东西',除非它被软键盘触发.如何判断软键盘是否触发了resize?

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.

这篇关于如何确定移动浏览器中的软键盘是否触发了调整大小事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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