Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính colorDepth của Screen trong HTML

Thuộc tính colorDepth của Screen trong HTML trả về độ sâu màu (bit depth) của bảng màu để hiển thị hình ảnh (tính bằng bits per pixel).

Cú pháp

Cú pháp như sau:

screen.colorDepth

Ví dụ

Dưới đây là ví dụ minh họa thuộc tính colorDepth của Screen:

<!DOCTYPE html>
<html>
<style>
  body {
    color: #000;
    height: 100vh;
    background-color: #FBAB7E;
    background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
    text-align: center;
  }
  .btn {
    background: #db133a;
    border: none;
    height: 2rem;
    border-radius: 2px;
    width: 40%;
    display: block;
    color: #fff;
    outline: none;
    cursor: pointer;
    margin: 1rem auto;
  }
  .show {
    font-size: 1.2rem;
    margin: 1rem auto;
    font-weight: bold;
    font-family: sans-serif;
  }
</style>
<body>
<h1>Thuộc tính screen.colorDepth trong HTML</h1>
<button class="btn" onclick="get()">Hiển thị độ sâu màu</button>
<div class="show"></div>
<script>
  function get() {
    document.querySelector(".show").innerHTML = "Độ sâu màu là " + screen.colorDepth + " bits per pixel";
  }
</script>
</body>
</html>

Kết quả

Thuộc tính colorDepth của Screen trong HTML

Nhấn vào nút "Hiển thị độ sâu màu" để hiển thị độ sâu màu của màn hình.

Thuộc tính colorDepth của Screen trong HTML