본문 바로가기

javascript, framework/jquery

Step06_animate (트랜지션, 이동)

 

 

Step06_animate 

 

<!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>Step06_animate.html</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            cursor: pointer;
            background-color: yellow;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<div class="box"></div>  
<script src="js/jquery-3.4.1.js"></script>
<script>
    //.box 를 클릭하면 크기가 width 와 height 가 200px 이 되도록 해보세요.
    // 단 순간적으로 변하는게 아니고 1초동안 서서히 200px 이 되게 하세요.
    // jquery 의 .animate() 동작을 검색해서 활용해 보세요.
    $(".box").click(function(){
        /*
            .animate(css property, duration, complete function)
        */

        $(this).animate({
            width:"200px",
            height:"200px",
            borderWidth:"10px"
        }, 1000, function(){
            alert("2배가 되었네요?");
        });
    });

</script>  
</body>
</html>

Step06_example

<!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>Step06_example.html</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background-color: yellow;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<button id="moveBtn">move</button> 
<button id="moveBtn2">move2</button>   
<div class="box"></div>
<script src="js/jquery-3.4.1.js"></script>
<script>
    /*
        move 버튼을 누르면 box div 가 우측으로 100px 씩 
        움직이도록 해 보세요.
        단, 움직이는 중간 과정이 보여야 됩니다.
    */

    var mLeft=0;

    $("#moveBtn").click(function(){

        mLeft += 100;

        $(".box").animate({
            marginLeft:mLeft+"px"
        });
    });

    $("#moveBtn2").click(function(){
        $(".box").animate({
            marginLeft:"+=100px"
        });
    });
</script>    
</body>
</html>

'javascript, framework > jquery' 카테고리의 다른 글

Step09_example  (0) 2022.09.16
Step08_regExp(정규표현식 활용 예제)  (0) 2022.09.16
Step07_form (폼)  (0) 2022.09.16
step05_effect (사라졌다 나타나는 효과들)  (0) 2022.09.16
Step01~04 (html, css 접근, event)  (0) 2022.09.16