[英]How to lose input focus when device orientates?
我注意到,當您專注於表單元素並更改方向時,iOS設備會鎖定網站的視圖。
我想知道是否有辦法修改已經實現的代碼,使其包含失去<input>
和<select>
專注於橫向(縱向還是縱向)功能的功能?
這是我已經擁有的代碼:
// Fix HTML width issues on device orientation
window.document.addEventListener('orientationchange', function() {
var iOS = navigator.userAgent.match(/(iPad|iPhone|iPod)/g);
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (iOS && viewportmeta) {
if (viewportmeta.content.match(/width=device-width/)) {
viewportmeta.content = viewportmeta.content.replace(/width=[^,]+/, 'width=1');
}
viewportmeta.content = viewportmeta.content.replace(/width=[^,]+/, 'width=' + window.innerWidth);
}
// If you want to hide the address bar on orientation change, uncomment the next line
window.scrollTo(0, 0);
}, false);
任何幫助將不勝感激,謝謝
尤里卡!
window.document.addEventListener('orientationchange', function(){
if (window.orientation === 90 || window.orientation === -90){
document.activeElement.blur();
}
else if(window.orientation === 0) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
viewportmeta.content = viewportmeta.content.replace(/width=[^,]+/, 'width=' + window.innerWidth);
}
window.scrollTo(0, 0);
}, false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.