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

[HTML_CSS] JQ - width() , height() , innerWidth() , innerHeight() , outerWidth() , outerHeight() 메서드 ★ - (너비,높이, 면적) 메서드

목차

  1. (너비/높이) 크기 관련 메서드 종류
  2. 예제1 - (너비/높이) 메서드 값 차이
  3. 예제2 - (document / window) 크기
  4. 예제3 - 요소의 (width / height) 설정


(너비/높이) 크기 관련 메서드 종류

 

  • width()  : 순수 요소 너비 (= 가로길이)
  • height()  : 순수 요소 높이 (= 세로길이) 

  • innerWidth()  : width + padding
  • innerHeight()  : height + padding 

  • outerWidth()  : width + padding + border 
  • outerHeight()  : height + padding + border 

  • outerWidth(true)  : width + padding + border + margin
  • outerHeight(true)  : height + padding + border + margin

 

PS. 주의: (padding, border, margin)은 각각 "좌우 (상하)" 고려해 계산.

 

예제1 - (너비/높이) 메서드 값 차이

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("button").click(function(){

        var txt = "";

        txt += "width(): " + $("#hz").width() + "</br>"; 

        txt += "height(): " + $("#hz").height() + "</br>"; 

        txt += "innerWidth(): " + $("#hz").innerWidth() + "</br>"; 

        txt += "innerHeight(): " + $("#hz").innerHeight() + "</br>"; 

        txt += "outerWidth(): " + $("#hz").outerWidth() + "</br>"; 

        txt += "outerHeight(): " + $("#hz").outerHeight() + "</br>";

        txt += "outerWidth(true): " + $("#hz").outerWidth(true) + "</br>";

        txt += "outerHeight(true): " + $("#hz").outerHeight(true);

        $("#hz").html(txt);

    });

});

</script>

<style>

#hz {

    height: 200px;

    width: 300px;

    padding: 10px;

    margin: 20px;

    border: 5px solid #f70542;

    background-color: #fff8f8;

    color:#f70542;

}

</style>


<div id="hz"></div> 

<button>div 요소의 순수 면적 표시</button>


결과 보기

 

예제2 - (document / window) 크기

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("button").click(function(){

        var txt = "";

        txt += "Document 너비x높이: " + $(document).width();

        txt += "x" + $(document).height() + "\n";

        txt += "Window 너비x높이: " + $(window).width();

        txt += "x" + $(window).height();

        alert(txt);

    });

});

</script>


<button>document와 window 면적 표시</button>


결과 보기

※ alert (얼럿창 = 경고창)에서는 줄바꿈을 \n 사용

 

예제3 - 요소의 (width / height) 설정

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("button").click(function(){

        $("#hz").width(200).height(25);

    });

});

</script>

<style>

#hz {

    height: 100px;

    width: 300px;

    padding: 10px;

    margin: 20px;

    border: 5px solid #f70542;

    background-color: #fff8f8;

    color: #f70542;

}

</style>


<div id="hz">홈짱닷컴 Homzzang.com</div>

<button>Resize div</button>


결과 보기


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
Effect JQ - stop() 메서드 ★ - 멈추게 하기 (= 슬라이드/애니 중단 = 움직임 멈추기/멈춤 = stop…
Effect JQ - Callback (콜백함수) ★ - 추가 호출 실행 함수
Effect JQ - Chaining 기법 ★ - 여러 메서드 연쇄 실행. (= 메서드 이어서 실행시키기. = 체이닝)
HTML_CSS JQ - text(), html(), val() , attr() 메서드 - (내용얻기/값얻기/속성얻기) (내… 2
HTML_CSS JQ - append(), prepend(), after(), before() 메서드 - (요소추가 / 내용…
HTML_CSS JQ - remove() / empty() 메서드 - (요소제거 / 내용삭제 / 내용비우기) ※ 리무브, 엠…
HTML_CSS JQ - addClass() , removeClass() , toggleClass() , css() 메서드 …
HTML_CSS JQ - css() 메서드 ★★★ - CSS 설정/반환 (= CSS메서드 = 스타일메서드) ※ 스타일 주기
HTML_CSS JQ - width() , height() , innerWidth() , innerHeight() , out…
Traversing JQ - Traversing - 특정요소찾기 (= 특정요소선택 = 트래버싱)
Traversing JQ - parent() , parents() , parentsUntil() 메서드 - 부모요소찾기 (= 부…
Traversing JQ - children() 메서드 - 자식요소찾기 / find() 메서드 - 자손요소찾기
Traversing JQ - 형제찾기 메서드 - siblings() , next() , nextAll() , nextUntil(…
Traversing JQ - 검색필터링 메서드 - first() , last() , eq() , filter() , not() …
AJAX JQ - AJAX (아작스) 소개 - 정의 / 기본예제 / 메서드종류
AJAX JQ - load() 메서드 ★ - 파일 내용 가져오기 (= load메서드 = 아작스 로드메서드)
AJAX JQ - get()/post() 메서드 - 서버에 정보요청 (= get메서드 = 겟메서드 / post메서드 …
Misc JQ - noConflict() 메서드 ★★★ - javascript (JS) 기반의 다른 프레임워크와의 충…
Examples jQuery Examples - 제이쿼리 예제 복습
Examples JQ - Quiz - 제이쿼리 퀴즈테스트
2/15
목록
찾아주셔서 감사합니다. Since 2012