I'm

Developer, Designer, Photographer

GET IN TOUCH

  • Buk-gu, Busan, Republic of Korea
  • ungdoli0916@naver.com
  • Kakao ID : Ungdoli
Your message has been sent. Thank you!
(즐거웅코드) 제이쿼리 가장 큰 height를 찾아 동일하게 맞추기

· 즐거'웅' 코드 (Source)/HTML & CSS & JAVASCRIPT
2021. 7. 31. 00:10

반응형

[즐거'웅'코드] 목차

  1. 예제 소스
  2. 구현 예시
예제 소스
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
 
<style>
    .wrapper {
        display: inline-block;
        width: 100%;
        margin-bottom: 20px;
    }
 
    .wrapper .box {
        float: left;
        display: inline-block;
        width: 200px;
    }
 
    .wrapper .box:nth-child(1) {
        background-color: #F26F3D;
        height: 200px;
    }
 
    .wrapper .box:nth-child(2) {
        background-color: #d9f290;
        height: 140px;
    }
 
    .wrapper .box:nth-child(3) {
        background-color: #b8e7f2;
        height: 80px;
    }
</style>
 
<div class="wrapper">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
</div>
 
<button onclick="test()">객체들 중 가장 큰 height를 찾아 동일하게 맞추기</button>
 
<script>
    function test() {
        var height_array = $(".wrapper .box").map(function () {
            return $(this).height();
        }).get();
 
        var max_height = Math.max.apply(Math, height_array);
        $(".wrapper .box").height(max_height);
    }
</script>
구현 예시
반응형