IOS系統下虛擬鍵盤遮擋文字框問題的解決

來源:互聯網
上載者:User

標籤:寫法   val   focus   name   blur   nbsp   scroll   document   指點   

最近在項目中發現同樣的代碼在Android端網頁中點擊文字框喚出的虛擬鍵盤不會遮擋文字框,但是在IOS端的網頁中點擊文字框喚出的鍵盤卻在大部分情況下會遮擋文字框

經過高人指點,這個問題終於解決了

下面說說解決辦法:

主要代碼

 

document.body.scrollTop = document.body.scrollHeight;

 

然後在文字框擷取焦點的時候,可以定義一個計時器,一直執行上面的那句話

在文字框失去焦點的時候,就把之前的計時器清除掉即可

js寫法:

let interval;

//擷取文字框對象
let text = document.getElementById(‘text‘).getElementsByTagName(‘textarea‘)[0];
//訊息框擷取焦點
text.onfocus = function () {
interval = setInterval(function () {
scrollToEnd();
}, 500)
};

//訊息框失去焦點
text.onblur = function () {
clearInterval(interval);
};

//滾動到底部
function scrollToEnd() {
document.body.scrollTop = document.body.scrollHeight;
}

 

jquery寫法:

let interval;
let text = $(‘#text textarea‘);
//訊息框擷取焦點
text.focus (function(){
interval = setInterval(function () {
scrollToEnd();
}, 500)
});

//訊息框失去焦點
text.onblur(function () {
clearInterval(interval);
});

//滾動到底部
function scrollToEnd() {
document.body.scrollTop = document.body.scrollHeight;
}

 

IOS系統下虛擬鍵盤遮擋文字框問題的解決

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.