jQuery 수업

jQuery-8(animate())

줄라이퍼스트 2020. 2. 19. 11:55

※ animate를 사용하려면 position를 꼭 absoulte로 선언을 해야함

애니메이트 예제(4번 실행화면) - 클릭하시면 자세히 볼 수 있습니다.

1. 애니메이트 예제

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
      $(document).ready(function(){
            $("button").click(function(){
                // animate 대상 tag의 display속성을 absoulte로 선언해야함
                $("div").animate({left: '250px'});
            });         

    });
    </script>

    
</head>
<body>
    <button>Start Animation</button>

    <p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
    <!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
    <div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
    

</body>
</html>

 

1. 실행화면

 

애니메이트 예제(1번 실행화면) - 클릭하시면 자세히 볼 수 있습니다.

 

2. 애니메이트 예제

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
      $(document).ready(function(){
            $("button").click(function(){
                $("div").animate({
                    
                    left: '250px',
                    opacity: '0.5',
                    height: '150px',
                    width: '150px'

                });
            });
    });
    </script>

    
</head>
<body>
    <button>Start Animation</button>

    <p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
    <!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
    <div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
    

</body>
</html>

2. 실행화면

 

애니메이트 예제(2번 실행화면) - 클릭하시면 자세히 볼 수 있습니다.

 

3. 애니메이트 예제

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
      $(document).ready(function(){
            $("button").click(function(){
                $("div").animate({

                    left: '250px',
                    opacity: '0.5',
                    // += 150 px => height += 150px
                    // height: '150px',
                    height : 'toggle',
                    width: '+=150px'

                });
            });
    });
    </script>

    
</head>
<body>
    <button>Start Animation</button>

    <p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
    <!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
    <div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
    

</body>
</html>

 

3. 실행화면

 

 

애니메이트 예제(3번 실행화면) - 클릭하시면 자세히 볼 수 있습니다.

 

 

 

4. 애니메이트 예제

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $("button").click(function(){
                // div : div tag에 해당하는 object(객체)를 말함
                var div = $("div");
                div.animate({height:'300px',opacity:'0.4'}, "slow");
                div.animate({width:'300px',opacity:'0.8'}, "slow");
                div.animate({height:'100px',opacity:'0.4'}, "slow");
                div.animate({width:'100px',opacity:'0.8'}, "slow");
            });            
        });
    </script>
</head>
<body>
    
    <button>Start Animation</button>
    <p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
    <!-- 애니메이션을 사용하려면 postion:absolute를 꼭 써줘야함!!-->
    <div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>

</body>
</html>

애니메이트 예제(4번 실행화면) - 클릭하시면 자세히 볼 수 있습니다.