property offsetWidth ของ HTML DOM Element
- หน้าก่อนหน้า offsetHeight
- หน้าต่อไป offsetLeft
- กลับไปยังเวอร์ชั่นก่อนหน้า วัตถุ HTML DOM Elements
คำนิยามและวิธีใช้
offsetWidth
property นี้กลับค่ากว้างขององค์ประกอบ (เป็นพิกัดเป็นพิกเซล) ที่ที่มองเห็นขององค์ประกอบ รวมถึงพาดิ้งและเส้นขอบ และหลอดเลื่อน แต่ไม่รวมถึงมุมนอก
offsetWidth
property นี้เป็นที่เข้าอ่านเท่านั้น
ดูเพิ่มเติมที่:ตัวอย่างฝึกสอน CSS Box Model
offsetParent
ทุกองค์ประกอบของเซลล์ที่เป็นบล็อครายงานตำแหน่งเรียบเรียงต่อพ่อเมื่องย้ายตำแหน่งของเขา:
- offsetTop
- offsetLeft
- offsetWidth
- offsetHeight
พ่อเมื่องย้ายตำแหน่งหมายถึงพ่อเมื่องที่ใกล้ที่สุดที่มีตำแหน่งย้ายตำแหน่งไม่เป็นสถานะที่ยังไม่เคยถูกย้ายตำแหน่ง
ถ้าไม่มีพ่อเมื่องย้ายตำแหน่ง ตำแหน่งเป็นต่อตัวเองของบทความของเอกสาร
ดูเพิ่มเติมที่:
ตัวอย่าง
ตัวอย่าง 1
เรียกใช้ "myDIV" สูงและกว้าง รวมถึงพาดิ้งและเส้นขอบ:
const elmnt = document.getElementById("myDIV"); let text = "สูงด้วยพาดิ้งและเส้นขอบ: " + elmnt.offsetHeight + "px<br>"; text += "Width with padding and border: " + elmnt.offsetWidth + "px";
ตัวอย่าง 2
ความแตกต่างระหว่าง clientHeight/clientWidth และ offsetHeight/offsetWidthไม่มีสไตล์เลื่อน
const elmnt = document.getElementById("myDIV"); let text = ""; text += "Height with padding: " + elmnt.clientHeight + "px<br>"; text += "Height with padding and border: " + elmnt.offsetHeight + "px<br>"; text += "Width with padding: " + elmnt.clientWidth + "px<br>"; text += "Width with padding and border: " + elmnt.offsetWidth + "px";
มีสไตล์เลื่อน
const elmnt = document.getElementById("myDIV"); let text = ""; text += "Height with padding: " + elmnt.clientHeight + "px<br>"; text += "Height with padding, border and scrollbar: " + elmnt.offsetHeight + "px<br>"; text += "Width with padding: " + elmnt.clientWidth + "px<br>"; text += "Width with padding, border and scrollbar: " + elmnt.offsetWidth + "px";
รูปแบบการใช้
element.offsetWidth
ค่าที่กลับมา
ชนิด | การอธิบาย |
---|---|
ตัวเลข | ความกว้างขององค์ประกอบที่มีความเห็นได้เห็น (เป็นพิกซ์เอล) รวมถึงส่วนหลังเครื่องงาน ของเข็มตัว และตราสารเลื่อน |
การสนับสนุนเบราเซอร์
ทุกเบราเซอร์ทุกทีม element.offsetWidth
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน |
- หน้าก่อนหน้า offsetHeight
- หน้าต่อไป offsetLeft
- กลับไปยังเวอร์ชั่นก่อนหน้า วัตถุ HTML DOM Elements