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