fn

isInView

v0.0.5

Reports whether an element is fully within the visual viewport, accounting for on-screen keyboards via window.visualViewport. A 40px slack is allowed at the bottom to tolerate Safari's viewport quirks. Returns false when visualViewport is unavailable.

Example

ts
if (!isInView(focusedField)) scrollIntoView(focusedField);

Signature

ts
declare function isInView(element: HTMLElement): boolean;

Parameters

ParameterTypeDescription
elementHTMLElementThe element to test

Returns

booleantrue if the element's rect fits inside the visual viewport