Troubleshoot input and fixed issues on iOS

Source: Internet
Author: User

Under iOS If there is a fixed element at the bottom of the page when the input box triggers the keyboard, the fixed float appears in the page display always

There are a number of workarounds, but you need to change them according to actual needs

Method One, the CSS solves (the disadvantage: when has the large area INPUT element to have the sliding not to be smooth problem)

This sets the Position:absolute for the content area and sets a distance from the fixed bottom distance

. main{

Position:absolute;

Bottom:rem-calc (80px); The height of the fixed element

top:0;

left:0;

width:100%;

}

Method Two, JS solution (disadvantage: Each input focus event to be executed once)

. pos-rel {
Position:relative;;
}

<script>

$ (function () {
var Isios = (/iphone|ipad/gi). Test (navigator.appversion);//Determine if the iOS system

if (Isios) {
$ ('. Main '). On (' Focus ', ' input ', function () {
$ ('. Fixed-bottom '). addclass (' Pos-rel ');
}). On (' focusout ', ' input ', function () {
$ ('. Fixed-bottom '). Removeclass (' Pos-rel ');
});
}
});
</script>

Of course there are other solutions such as the use of iscroll.js at the beginning of the solution, and later found that in the INPUT element or the Click event Page introduced Iscroll.js will encounter a variety of pits are not recommended, of course, you can also set the fixed to absolute each time the page scrolling changes calculations, and this approach is also very resource-intensive

Combined with the above still feel that the page with input elements to avoid the use of fixed elements

Troubleshoot input and fixed issues on iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.