Viewport: thuộc tính segments

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính chỉ đọc segments của giao diện Viewport trả về một mảng đối tượng DOMRect đại diện cho vị trí và kích thước của mỗi phân đoạn viewport trong toàn bộ màn hình.

Giá trị

Một mảng đối tượng DOMRect.

Ví dụ

Cách dùng cơ bản Viewport.segments

Đoạn code này sẽ lặp qua từng phân đoạn trong viewport và ghi log một chuỗi vào console chi tiết số chỉ số, chiều rộng và chiều cao.

js
const segments = window.viewport.segments;

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

Thông số kỹ thuật

Thông số kỹ thuật
CSS Viewport Module Level 1
# dom-viewport-segments

Tương thích trình duyệt

Xem thêm