Back to Content

Viewport: segments property

files/en-us/web/api/viewport/segments/index.md

latest1.0 KB
Original Source

{{APIRef("Viewport Segments API")}}{{SeeCompatTable}}

The segments read-only property of the {{domxref("Viewport")}} interface returns an array of {{domxref("DOMRect")}} objects representing the position and dimensions of each viewport segment within the overall display.

Value

An array of {{domxref("DOMRect")}} objects.

Examples

Basic Viewport.segments usage

This snippet will loop through each segment in the viewport, and log a string to the console detailing the index number, width, and height.

js
const segments = window.viewport.segments;

segments.forEach((segment) =>
  console.log(
    `Segment ${segments.indexOf(segment)} is ${segment.width}px x ${segment.height}px`,
  ),
);

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also