SoFunction
Updated on 2025-04-14

Use scrollTop() to solve the problem of occluding input boxes in IOS

After testing, I found that some input methods on IOS browsers will pop up the input box. Many of the Internet introduce the following methods.

(function() { 
$(‘input').on(‘click', function () { 
var target = this; 
// Use timer to make it more natural when sliding the input box upsetTimeout(function(){ 
(true); 
},100); 
});

However, because I don’t understand scrollIntoView enough, the problem has not been solved. Later, I used the same idea to solve it using scrollTop().

Example:

<script language="javascript">`
$('#messageInput').on('click', function() {
// Use the timer because the pop-up of the input method will change the height of the body, so delay 1 second and wait until the input method pops up before positioning it at the bottom of the scroll bar    setTimeout(function() {
     $('body').scrollTop($('body')[0].scrollHeight);
    }, 1000);

});
</script>
<body>
<input type="text"  placeHolder="Please enter text" />
</body>

Summarize

The above is what the editor introduced to you to use scrollTop() to solve the problem of occluding input boxes in IOS. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!