본문 바로가기
안드로이드 웹앱 콘테츠 개발자 양성(국비지원)/JQuery

JQuery animate (이미지를 이동, 투명도, 크기 변경)

by 차누감 2019. 12. 18.

<최종 화면> 이미지를 이동, 투명도, 크기를 변경할 수 있다.


우선 이미지 1개와 버튼 6개를 만들자.

move버튼을 눌렀을 때, 왼쪽으로부터 200px떨어진 지점으로 이동되게 하자.

나머지 버튼의 기능들도 구현하자. 


<복붙용 코드>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
 
     <!-- JQuery 추가 -->
     <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
 
     <script>
         $(document).ready( function(){
            $('#move').on('click'function(){
            // **목표로 하는 css의 속성을 지정하면 자동으로 그 사이를 만들어주는
                 $('img').animate( {left:'200px'} );
            });
            $('#moveBack').on('click'function(){
           
                 $('img').animate( {left:''}, 3000 ); //duration
            });
            $('#multiAni').on('click'function(){
           
                 $('img').animate( {left:'+=50px', opacity:'0.4', width:'+=50px', height:'-=50px'}, 3000 ); //duration
            });
            $('#sequential').on('click'function(){
                 $('img').animate( {left:'+=30px'}, 1000 ); 
                 $('img').animate( {opacity:'0.4'}, 1000 ); 
                 $('img').animate( {width:'+=50px'}, 1000 ); 
                 $('img').animate( {height:'-=50px'}, 1000 ); 
            });
            //리셋
            $('#reset').on('click'function(){
                $('img').animate( {left:'', opacity:'1.0', width:'200px', height:'200px'}, 3000 );
             });
 
            $('#stop').on('click'function(){
                 $('img').stop();
            });
 
 
         });
     </script>
 
</head>
<body>
 
    <p>
        <button id="move">move</button>
        <button id="moveBack">moveBack</button>
        <button id="multiAni">multiAni</button>
        <button id="sequential">sequential</button>
        <button id="reset">reset</button>
        <button id="stop">stop</button>
    </p>
    <img src="./ms17.png" width="200" style="position: relative;">
    
</body>
</html>
 

댓글