본문 바로가기
jQuery 제이쿼리

[객체] 함수를 활용한 속성 부여

by chloeize 2021. 5. 12.
728x90

구현 1 
구현 1 - cord

 

 

    <img src="" alt="" class="text_box">

    <img src="" alt="" class="text_box">

    <img src="" alt="" class="text_box">

 

    <script>

 

        $(document).ready(function (){

            $('.text_box').attr('height'function(index){ 

                // 단계적으로 크기 적용

                return (index + 1) * 100;

                // 인덱스 0인 .text_box == (0+1) * 100 => height : 100px

            })

        })

    </script>

 

 

구현 2
구현 2 - cord

 <script>

 

        $(function(){

            $('img').attr({

                width : function (index) {

                    return (index + 1) * 100;

                },

                height : 100

            });

        });

    </script>




728x90