js document.activeElement及使用


// 解決鍵盤彈出后擋表單的問題 

// 解決鍵盤彈出后擋表單的問題
    window.addEventListener('resize', function() {
      if(
        document.activeElement.tagName === 'INPUT' ||
        document.activeElement.tagName === 'TEXTAREA'
      ) {
        window.setTimeout(function() {
          if('scrollIntoView' in document.activeElement) {
            document.activeElement.scrollIntoView();
          } else {
            document.activeElement.scrollIntoViewIfNeeded();
          }
        }, 0);
      }
    });

  document.activeElement 的支持程度,發現四大瀏覽器safari除外, ie firefoxopera都提供了這個對象的支持。但是有點需要注意的,上面的例子中 opera 會把圖片作為 可以 focus的對象。導致document.activeElement的結果不一致...

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM