Solving the problem of virtual keyboard occlusion text box under iOS system

Source: Internet
Author: User

Recently found in the project the same code in the Android Web page click on the text box to call out the virtual keyboard will not obscure the text box, but in the iOS side of the page click on the text box called the keyboard but in most cases will obscure the text box

After the expert guidance, the problem finally solved

Here's the solution:

Main code

Document.body.scrollTop = Document.body.scrollHeight;

Then when the text box gets the focus, you can define a timer that executes the sentence above

When the text box loses focus, remove the previous timer

JS notation:

Let interval;

Get text Box Object
Let text = document.getElementById (' text '). getElementsByTagName (' textarea ') [0];
message box Get focus
Text.onfocus = function () {
Interval = setinterval (function () {
Scrolltoend ();
}, 500)
};

message box loses focus
Text.onblur = function () {
Clearinterval (interval);
};

Scroll to the bottom
function Scrolltoend () {
Document.body.scrollTop = Document.body.scrollHeight;
}

jquery notation:

Let interval;
Let Text = $ (' #text textarea ');
message box Get focus
Text.focus (function () {
Interval = setinterval (function () {
Scrolltoend ();
}, 500)
});

message box loses focus
Text.onblur (function () {
Clearinterval (interval);
});

Scroll to the bottom
function Scrolltoend () {
Document.body.scrollTop = Document.body.scrollHeight;
}

Solving the problem of virtual keyboard occlusion text box under iOS system

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.