ล่าสุดการพัฒนาเว็บบทเรียน
×

JavaScript การอ้างอิง

ภาพรวม

JavaScript

JS เชือก JS จำนวน JS ผู้ประกอบการ JS งบ JS คณิตศาสตร์ JS วันที่ JS แถว JS บูลีน JS นิพจน์ทั่วไป JS สถานการณ์โดยรวม JS การแปลง

เบราว์เซอร์ BOM

Window Navigator Screen History Location

HTML DOM

DOM เอกสาร DOM องค์ประกอบ DOM แอตทริบิวต์ DOM เหตุการณ์ DOM รูปแบบ

HTML วัตถุ

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <keygen> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <td> <th> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

วัตถุอื่น ๆ

CSSStyleDeclaration


 

HTML DOM clientHeight Propery

<ธาตุวัตถุ

ตัวอย่าง

ได้รับความสูงและความกว้างของ <div> องค์ประกอบรวมทั้ง padding:

var elmnt = document.getElementById("myDIV");
var txt = "Height with padding: " + elmnt.clientHeight + "px<br>";
txt += "Width with padding: " + elmnt.clientWidth + "px";

ผลจากการ txt จะเป็น:

Height with padding: 270px
Width with padding: 420px
ลองตัวเอง»

เพิ่มเติม "Try it Yourself" ตัวอย่างด้านล่าง


ความหมายและการใช้งาน

สถานที่ให้บริการ clientHeight ผลตอบแทนที่สูงสามารถมองเห็นได้ขององค์ประกอบในพิกเซลรวมทั้งการขยาย แต่ไม่ชายแดนแถบเลื่อนหรือคิดเป็นอัตรา

สาเหตุที่ "viewable" เป็นคำที่ระบุเป็นเพราะถ้าเนื้อหาองค์ประกอบคือสูงกว่าความสูงที่แท้จริงของธาตุแห่งนี้จะกลับมามีความสูงที่สามารถมองเห็นได้ (See "More Examples")

หมายเหตุ: เพื่อให้เข้าใจถึงคุณสมบัตินี้คุณต้องเข้าใจ กล่อง CSS รุ่น

เคล็ดลับ: คุณสมบัตินี้มักจะใช้ร่วมกับ clientWidth คุณสมบัติ

เคล็ดลับ: ใช้ offsetHeight และ offsetWidth คุณสมบัติที่จะกลับมามีความสูงสามารถดูได้และความกว้างขององค์ประกอบรวมทั้งการขยายพรมแดนและเลื่อน

เคล็ดลับ: การเพิ่มแถบเลื่อนไปยังองค์ประกอบให้ใช้แบบ CSS ล้น สถานที่ให้บริการ

สถานที่แห่งนี้เป็นอ่านอย่างเดียว


สนับสนุนเบราว์เซอร์

คุณสมบัติ
clientHeight ใช่ ใช่ ใช่ ใช่ ใช่

วากยสัมพันธ์

element .clientHeight

รายละเอียดทางเทคนิค

กลับค่า: หมายเลขที่เป็นตัวแทนของความสูงที่สามารถดูได้ขององค์ประกอบในพิกเซลรวมทั้งการขยาย

ตัวอย่าง

ตัวอย่างอื่น ๆ

ตัวอย่าง

ตัวอย่างนี้แสดงให้เห็นถึงความแตกต่างระหว่าง clientHeight / clientWidth และ offsetHeight / offsetWidth นี้:

var elmnt = document.getElementById("myDIV");
var txt = "";
txt += "Height with padding: " + elmnt.clientHeight + "px<br>";
txt += "Height with padding and border: " + elmnt.offsetHeight + "px<br>";
txt += "Width with padding: " + elmnt.clientWidth + "px<br>";
txt += "Width with padding and border: " + elmnt.offsetWidth + "px";

ผลจากการ txt จะเป็น:

Height with padding: 270px
Height with padding and border: 280px
Width with padding: 420px
Width with padding and border: 430px
ลองตัวเอง»

ตัวอย่าง

ตัวอย่างนี้แสดงให้เห็นถึงความแตกต่างระหว่าง clientHeight / clientWidth และ offsetHeight / offsetWidth เมื่อเราเพิ่มแถบเลื่อนเพื่อองค์ประกอบ:

var elmnt = document.getElementById("myDIV");
var txt = "";
txt += "Height with padding: " + elmnt.clientHeight + "px<br>";
txt += "Height with padding, border and scrollbar: " + elmnt.offsetHeight + "px<br>";
txt += "Width with padding: " + elmnt.clientWidth + "px<br>";
txt += "Width with padding, border and scrollbar: " + elmnt.offsetWidth + "px";

ผลจากการ txt จะเป็น:

Height with padding: 249px
Height with padding, border and scrollbar: 280px
Width with padding: 399px
Width with padding, border and scrollbar: 430px
ลองตัวเอง»

<ธาตุวัตถุ