[英]Prevent screen scrolling up when keyboard is shown in mobile Safari
我正在構建一個Angularjs應用程序,它在一個視圖的底部。
iOS9上移動游俠中的問題:當聚焦textarea時,顯示軟鍵盤並覆蓋視圖的下半部分。
當鍵盤可見時,如何向上滾動頁面以便不覆蓋內容(即textarea)?
這是阻止滾動的一種方法。 添加overflow:hidden
當輸入處於焦點時overflow:hidden
到文檔正文。
function toArray (collection) { return Array.prototype.slice.call(collection); } function noScroll (event) { if (event.type === 'focus') { document.body.classList.add('no-scroll'); } else if (event.type === 'blur') { document.body.classList.remove('no-scroll'); } } var inputs = toArray(document.querySelectorAll('input')); inputs.forEach(function(input){ input.addEventListener('focus',noScroll,false); input.addEventListener('blur',noScroll,false); });
.no-scroll { overflow:hidden; }
要向上滾動頁面,可以在輸入處於焦點時使用document.body.scrollTop
並將值設置為所需位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.