Skip to content

Viewport Info

ts
import { viewportInfo } from "mobx-web-api";

Allows tracking visual viewport dimensions and scale.

What's inside

Uses Visual Viewport API under the hood.

Usage

ts
import { viewportInfo } from "mobx-web-api";
import { reaction } from "mobx";

reaction(
  () => viewportInfo.height,
  (height) => {
    console.log(`visual viewport height: ${height}`);
  }
);

Properties

isSupported

true when window.visualViewport exists.

MDN Reference

width / height

Visual viewport size.

offsetLeft / offsetTop

Offset of visual viewport relative to layout viewport.

pageLeft / pageTop

Coordinates of visual viewport relative to initial containing block.

scale

Current pinch-zoom scale factor.

MDN Reference

isKeyboardLikeOverlay

Heuristic flag that becomes true when visual viewport is much smaller than layout viewport.

Notes

  • If VisualViewport API is unavailable, falls back to window.innerWidth/innerHeight.
  • Keyboard overlay detection is heuristic and may vary by browser.

Released under the MIT License.