HTML DOM Element clientHeight
❮ Obiekt elementuPrzykład
Uzyskaj wysokość i szerokość „myDIV”, w tym dopełnienie:
const elmnt = document.getElementById("myDIV");
let text = "Height with padding: " + elmnt.clientHeight + "px<br>";
text += "Width with padding: " + elmnt.clientWidth + "px";
Więcej przykładów poniżej.
Definicja i użycie
Właściwość clientHeight
zwraca widoczną wysokość elementu w pikselach, w tym dopełnienie, ale nie obramowanie, pasek przewijania ani margines.
Właściwość clientHeight
jest tylko do odczytu.
Instruktaż:
Zobacz też:
Właściwość Element clientWidth
Właściwość elementu offsetHeight
Aby dodać paski przewijania do elementu, użyj właściwości CSS overflow .
Składnia
element.clientHeight
Wartość zwrotu
Rodzaj | Opis |
Numer | Widoczna wysokość elementu (w pikselach), w tym dopełnienie |
Różnica między clientHeight/clientWidth a offsetHeight/offsetWidth
Bez paska przewijania:
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";
Z paskiem przewijania:
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";
Obsługa przeglądarki
element.clientHeight
jest obsługiwany we wszystkich przeglądarkach:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
❮ Obiekt elementu