Viewport Segments API
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.
Value
An array of 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.
const segments = window.viewport.segments;
segments.forEach((segment) =>
console.log(
`Segment ${segments.indexOf(segment)} is ${segment.width}px x ${segment.height}px`,
),
);
Specifications
Browser compatibility
See also
- Viewport Segments API
- CSSOM view API
- Origin trial for Foldable APIs via developer.chrome.com (2024)
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
