ใช้ Property screen.pixelDepth เพื่อดึงความลึกของสี (Bits per Pixel) ของหน้าจอผู้ใช้
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<body>
<script>
document.write("Screen width: " + screen.width);
document.write("<br>Screen height: " + screen.height);
document.write("<br>Pixel Depth: " + screen.pixelDepth);
</script>
</body>
</html>
คำอธิบาย Properties
| Property | ความหมาย | ค่าตัวอย่าง |
|---|---|---|
screen.width | ความกว้างหน้าจอ (px) | 1920 |
screen.height | ความสูงหน้าจอ (px) | 1080 |
screen.pixelDepth | Bit ต่อ Pixel (Color Depth) | 24, 30, 32 |
screen.colorDepth | Bit ต่อสี (มักเท่ากัน) | 24 |
ค่าที่พบบ่อย
- 24-bit: True Color (16.7M สี) — มาตรฐานปัจจุบัน
- 30-bit: Deep Color (1.07B สี) — หน้าจอ High-end
- 32-bit: 24-bit Color + 8-bit Alpha Channel
- 16-bit: High Color (65K สี) — เก่า/Embedded
ความแตกต่าง pixelDepth vs colorDepth
pixelDepth— Bit ทั้งหมดต่อ Pixel (รวม Alpha/Padding)colorDepth— Bit ใช้แสดงสีจริง (มักเท่ากันใน Browser สมัยใหม่)
หมายเหตุ: ค่าเหล่านี้อ่านจาก Hardware/OS ไม่ใช่ Browser Zoom Level