คุณสมบัติ AvailWidth ของหน้าจอ HTML จะคืนค่าความกว้างที่ใช้ได้ของหน้าจอของผู้ใช้ ซึ่งหมายความว่าจะไม่รวมฟีเจอร์อินเทอร์เฟซของเบราว์เซอร์
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
screen.availWidth
ตัวอย่าง
ให้เราดูตัวอย่างของคุณสมบัติความกว้างหน้าจอ HTML -
<!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>HTML screen availWidth Property</h1>
<button class="btn" onclick="get()">Show availWidth Value</button>
<div class="show"></div>
<script>
function get() {
document.querySelector(".show").innerHTML = "Available Width is " + screen.availWidth + " px";
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ “แสดงค่า availWidth ” เพื่อแสดงค่าของคุณสมบัติ availWidth -
