Home > Web Front-end > JS Tutorial > JS solves the relevant example code of mobile phone input box pop-up in mobile web development

JS solves the relevant example code of mobile phone input box pop-up in mobile web development

零下一度
Release: 2017-04-19 11:09:59
Original
1696 people have browsed it

The difference between mobile web development and the PC side is that the input on the mobile phone is a soft keyboard, so there will be a problem, that is, when there is input, the keyboard will pop up, and the entire page will inevitably change. How to solve this problem? Below, the editor of Script House will share with you JS to solve the problem of the mobile phone input box popping up in mobile web development

The difference between mobile web development and the PC side is that the input on the mobile phone is a soft keyboard, so there will be The problem is that when there is input, the keyboard pops up and the entire page will inevitably change.

1. When the background of the page is increased, the background will not be enough.

The solution is in the body Set the background image. Even if the page is raised, the background will still exist.

2. Use fix layout at the bottom

This problem will cause the page to be raised and the fix at the bottom to be raised accordingly, covering the corresponding There are two solutions for this

One is to increase the page accordingly. How much the page changes should we let the page above scroll,


$('input').bind('click',function(e){
  var $this = $(this);
  e.preventDefault();
  setTimeout(function(){
    $(window).scrollTop($this.offset().top - 10);
  },200)
})
Copy after login

$this.offset().top is the height of the input element, scroll the window to the position of the input to be input

two , hide the fix element and then display it when the page input is completed


##

var original = document.documentElement.clientHeight;
window.addEventListener("resize", function() {
var resizeHeight = document.documentElement.clientHeight;
if(resizeHeight != original) {
$('.bottom-button').css('display', 'none');
} else {
$('.bottom-button').css('display', 'block');
}
});
Copy after login
Using the resize attribute, when the mobile phone input box pops up, the page screen will be deformed , resize will be executed. We first get the original height. When it changes, we get the current page height. When the page height is different, we hide the element.

The above is the detailed content of JS solves the relevant example code of mobile phone input box pop-up in mobile web development. 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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template