210403 JavaScript jQuery Animate 연습_1

ITisIT210·2021년 4월 3일
0

jQuery

목록 보기
10/142
post-thumbnail
<!DOCTYPE html>
<html lang="en">
    <head>
            <meta charset="UTF-8">
            <title>Document</title>
            <style>
                div {
                    width: 200px;
                    height: 200px;
                    background-color: yellow;
                    margin: 50px auto;
                }
            </style>
    </head>
    <boby>
        <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 src="js/jquery-ui.min.js"></script> 

        <script>
            //animate : 요소를 움직여주는 것, css 값에 변화를 줌, 콜백이 가능함

            $(".box1").on("click", function() {
                $(this).animate({
                "width" : "300px",
                "height" : "100px"
            }, 2000);
            });

            $(".box2").on("click", function() {
                $(this).animate({
                    "width" : "500px"
                }, 1000, function() {
                    //animate가 종료되고 나서 일어날 이벤트
                    $(this).animate({
                        "height" : "300px" //1초 뒤에 높이 값이 변화
                    })
                });
            });

            $(".box3").on("click", function() {
                $(this).animate({
                    "width" : "600px"
                }, 1000, "easeOutBounce", function() { //시간, easing, 함수

                }); //jQuery로만 사용 가능한 easing키워드, https://easings.net/
            });

            //$(".box4").dragable();
            
            $(".box5").on("mouseover", function() {
                $(this).stop().animate({ //stop()함수
                    "width" : "600px"
                });
            }).on("mouseout", function() {
                $(this).stop().animate({
                    "width" : "200px"
                });
            });

        </script>
    </boby>
    </html>
profile
Engineering is the closest thing to magic that exists in the world.

0개의 댓글