PreferenceManager: thuộc tính contrast

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

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Thuộc tính chỉ đọc contrast của giao diện PreferenceManager trả về một PreferenceObject dùng để ghi đè tùy chọn của người dùng về độ tương phản của trang web.

Các cài đặt PreferenceObject.value hợp lệ cho contrastmore, lessno-preference.

Giá trị

Một PreferenceObject dùng để ghi đè tùy chọn của người dùng về độ tương phản của trang web.

Ví dụ

Sử dụng cơ bản

Ví dụ này minh họa cách truy vấn tùy chọn độ tương phản của người dùng.

js
if (navigator.preferences.contrast.value === "more") {
  // The user prefers a high color contrast.
} else if (navigator.preferences.contrast.value === "less") {
  // The user prefers a low color contrast.
} else {
  // The user has stated no preference regarding color contrast.
}

Thông số kỹ thuật

Thông số kỹ thuật
Media Queries Level 5
# contrast-attribute

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