얼렁뚱땅코드/jquery

제이쿼리 애니메이션: callback을 이용해서 움직이는 선 박스 만들기

얼렁뚱땅 디자이너 2019. 9. 26. 21:41

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

    <link rel="stylesheet" href="reset.css">

    <style>

        *{box-sizingborder-box;}

        body{height:100vh;}

        .section1{width740pxpositionrelative;

                left50%top:50%transformtranslate(-50%,-50%);}

        .section1 img{width100%opacity:0;}

 

        .section1 p{positionabsolutebackground#000;}

        p.top{width: ; height1pxleft:0top:0; }

        p.right{width1pxheight: ; right:0top:0;}

        p.bottom{width: ; height1pxright:0bottom0;}

        p.left{width1pxheight: ; left:0bottom:0;}

 

    </style>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <script>

       $(function(){

            $('p.top').animate({'width':'100%'},1000,function(){

                $('p.right').animate({'height':'100%'},function(){

                    $('p.bottom').animate({'width':'100%'},function(){

                        $('p.left').animate({'height':'100%'},function(){

            

                        });

                    });

                });

            });

       });

    </script>

</head>

<body>

   <section class="section1">

    <p class="top"></p>

    <p class="right"></p>

    <p class="bottom"></p>

    <p class="left"></p>

    <img src="img/section1.png" alt=""/>

   </section>

</body>

</html>

 

 

스크립트를 아래처럼 그리면 순서대로 박스를 그려준다.

<script>

       $(function(){

            $('p.top').animate({'width':'100%'},1000,function(){

                $('p.right').animate({'height':'100%'},function(){

                    $('p.bottom').animate({'width':'100%'},function(){

                        $('p.left').animate({'height':'100%'},function(){

            

                        });

                    });

                });

            });

       });

    </script>

 

스크립트를 아래처럼 그리면 동시에 선 그리기가 시작되어 박스를 그려준다.

<script>

       $(function(){

            $('p.top').animate({'width':'100%'},1000,function(){});

            $('p.right').animate({'height':'100%'},function(){});

            $('p.bottom').animate({'width':'100%'},function(){});

            $('p.left').animate({'height':'100%'},function(){});

       });

    </script>