logo
Published on

スマホを縦横にしても正しく window.innerWidth を取得する

著者
  • profile
    名前
    平原典彦
スマホを縦横にするとwindow.innerWidthが正しく取得できなかったので、正しく取得できるようにしてみました。
window.screenを利用して取得します。
const widths = [window.innerWidth] if (window.screen?.width) { widths.push(window.screen?.width) } const width = Math.min(...widths)