210404 JavaScript jQuery Width-Height 연습_2

ITisIT210·2021년 4월 5일
0

jQuery

목록 보기
24/142
post-thumbnail
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{
            background-color: dodgerblue;
            margin: 50px auto;
        }
        
        .box1{width: 50px; height: 300px;}
        .box2{width: 120px; height: 600px;}
        .box3{width: 400px; height: 200px;}
        .box4{width: 300px; height: 150px;}
        .box5{width: 700px; height: 234px;}
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
    <div class="box5"></div>
    
    
    <script src="js/jquery-3.6.0.min.js"></script>
    <script>
        /*
            $(sel).width() 해당 선택자의 너비값을..
            $(sel).width(num) 너비값 반영.
            
            $(sel).height()
            $(sel).height(num)
        */
        
        $("div").on("click", function() {
            var a = $(this).is(":animated");
            // is() 선택자의 상태를 묻는 메서드
            // true or false로 반환.
            
            if(a === false){//animate상태x
                var w = $(this).width();
                var h = $(this).height();
                
                $(this).stop().animate({
                    "width" : h,
                    "height" : w
                })
            }
        })
    </script>
    
    
    
    
    
    
    
    
    
    
</body>
</html>
profile
Engineering is the closest thing to magic that exists in the world.

0개의 댓글