• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Window_Object] JS - innerHeight 속성 ★ - 윈도우창 순수 내용영역 높이 반환 (= 내용높이 = 내부높이 = innerHeight속성 = 이너하이트속성) (IE9 이상)

목차
  1. innerHeight 예제 - 윈도우 높이 얻기
  2. innerHeight 정의
  3. innerHeight 구문
  4. innerHeight 예제 - 윈도우 관련 모든 너비/높이
  5. innerHeight 예제 - 이미지 화면 정중앙 배치

 

innerHeight 예제 - 윈도우 높이 얻기 

 

<button onclick="homzzang()">클릭</button>


<p id="demo"></p>


<script>

function homzzang() {

  var w = window.innerWidth;

  var h = window.innerHeight;

  var res = "Width: " + w + "<br>Height: " + h;

  document.getElementById("demo").innerHTML = res;

}

</script>

 

결과보기

 

innerHeight 정의

 

윈도우 콘텐츠 영역의 높이 반환.

 


 

1.

  • window 객체에 속함. (생략가능)
  • 읽기전용 속성임.

 

2. cf.

  • innerWidth 속성 - 순수 콘텐츠 영역만의 창 너비
  • innerHeight 속성 - 순수 콘텐츠 영역만의 창 높이
  • outerWidth 속성 - 툴바/스크롤바 등 포함한 창 너비
  • outerHeight 속성 - 툴바/스크롤바 등 포함한 창 너비


3.

IE9 이상 주요 최신 브라우저 모두 지원.

 

 

 

innerHeight 구문

 

  • window.innerHeight
  • innerHeight

 


[반환값]

브라우저 창 콘텐츠 영역의 내부 높이(px단위)를 나타내는 숫자 반환.

 

 

innerHeight 예제 - 윈도우 관련 모든 너비/높이

 

<div id="demo"></div>


<script>

let text =

"<p>innerWidth: " + window.innerWidth + "</p>" +

"<p>innerHeight: " + window.innerHeight + "</p>" +

"<p>outerWidth: " + window.outerWidth + "</p>" +

"<p>outerHeight: " + window.outerHeight + "</p>";


document.getElementById("demo").innerHTML = text;

</script>

 

결과보기

 

innerHeight 예제 - 이미지 화면 정중앙 배치

 

<style>

body { margin:0px; display:flex; justify-content:center; align-items:center; width:100%; }

img { display:block; max-width:100%; max-height:100%; object-fit:cover; }

</style>


<img src="https://picsum.photos/200/300" alt="랜덤이미지">

    

<script>

window.addEventListener("resize", bodySize = function() {

    document.querySelector("body").style.height = innerHeight * 0.99 + "px";

} );

bodySize();

</script>

 

결과보기

PS. 자세한 코드 설명은 아래 좌표들 참고.

 


분류 제목
Basic JS - 화살표함수 (Arrow Function) ★★★ (= Arrow함수 = 애로우함수|애로우펑션) (…
Basic JS - rest (나머지 기타등등) 매개변수
HTML_Objects JS - selectedIndex 속성 - 선택된 옵션 색인번호 (= selectedIndex속성 = 실렉…
Object JS - Object Display - 객체 표시(=출력)
Object JS - Object Classes - 객체 클래스
DOM_Element JS - dataset 속성 ★★★ - 데이터셋 속성 (= dataset속성) ※ div태그를 iframe태…
js JS - play(), pause() 메서드 - 동영상 재생/멈춤. (= play메서드, pause메서드 =…
Window_Object JS - devicePixelRatio 속성 ★ - 기기 픽셀 비율. ※ PC, 모바일 구별하기
js JS - 입력값 길이 제한 후, 경고창 띄우기
js JS - 눈 내리는 효과 (Snowflakes effect)
js JS - CSS 다크모드 토글 (Dark Mode Toggle) ※ 클래스 상호 대체/변환
DOM_Style JS - pointerEvents 속성 - 마우스 포인트 이벤트에 대한 반응 여부. (= pointerEve…
js JS - 스크롤 정도/위치 진행바 표시기 (Scroll Indicator Bar)
Form JS - input 태그의 name 속성값이 배열일 때, value값 가져오기 (= 폼태그 안 인풋 태그 네…
js JS - 숫자 (카운팅/변동) 애니 효과
DOM_Event JS - orientationchange 이벤트 - 장치 방향 바뀜 이벤트 (= 오리엔테이션체인지 이벤트) …
ScreenOrientation JS - ScreenOrientation 객체 - 장치 방향 정보 갖는 객체 (= 스크린오리엔테이션 객체)
ScreenOrientation JS - ScreenOrientation.type 속성 - 장치 방향 표시 (= 스크린오리엔테이션타입 속성)
ScreenOrientation JS - ScreenOrientation.angle 속성 - 문서의 현재 방향 각도 반환 (= 스크린오리엔테…
ScreenOrientation JS - ScreenOrientation.onchange 속성 ★ - 장치 방향 변경 이벤트 (= 스크린오리…
63/67
목록
찾아주셔서 감사합니다. Since 2012