Home > Web Front-end > H5 Tutorial > body text

H5制作虚拟键盘时出现输入框遮挡的情况怎么办?

Y2J
Release: 2017-05-22 13:55:27
Original
2648 people have browsed it

本文主要介绍了HTML5 虚拟键盘出现挡住输入框的解决办法。具有很好的参考价值,下面跟着小编一起来看下吧

话不多说,请看代码:

//防止键盘把当前输入框给挡住
$$('input[type="text"],textarea').on('click', function () {
  var target = this;
  setTimeout(function(){
        target.scrollIntoViewIfNeeded();
   },100);
});
Copy after login

部分安卓机型适用。

if(/Android [4-6]/.test(navigator.appVersion)) {
    window.addEventListener("resize", function() {
        if(document.activeElement.tagName=="INPUT" || document.activeElement.tagName=="TEXTAREA") {
            window.setTimeout(function() {
document.activeElement.scrollIntoViewIfNeeded();
            },0);
        }
    })
}
Copy after login

【相关推荐】

1. Html5免费视频教程

2. 关于H5新标签的浏览器兼容问题的详解

3. 教你如何用H5无刷新改变当前url的实例详解

4. 通过phonegap操作数据库的的教程详解

5. H5中indexedDB 数据库的使用方法详解

The above is the detailed content of H5制作虚拟键盘时出现输入框遮挡的情况怎么办?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!