Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The segments read-only property of the Viewport interface returns an array of DOMRect objects representing the position and dimensions of each viewport segment within the overall display.
An array of DOMRect objects.
Viewport.segments usageThis snippet will loop through each segment in the viewport, and log a string to the console detailing the index number, width, and height.
const segments = window.viewport.segments;
segments.forEach((segment) =>
console.log(
`Segment ${segments.indexOf(segment)} is ${segment.width}px x ${segment.height}px`,
),
);