티스토리 뷰

반응형
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!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>
    <style>
        .tab-menu {
             list-style: none;
             height:80px;
         }
         
         .tab-menu li {
             width:99px;
             height:40px;
             background-position-y:0;
             text-indent: -1000px;
             overflow: hidden;
             display: inline-block;
             float:left;
         }
         .tab-menu li.menuitem1 {
             background-image: url(image/newbtn.bar.1.png);    
         }
         .tab-menu li.menuitem2 {
             background-image: url(image/newbtn.bar.2.png);    
         }
         .tab-menu li.menuitem3 {
             background-image: url(image/newbtn.bar.3.png);    
         }
         .tab-menu li.menuitem4 {
             background-image: url(image/newbtn.bar.4.png);    
         }
         .tab-menu li.menuitem5 {
             background-image: url(image/newbtn.bar.6.png);    
         }
     </style>
    <script>
 
        //이미지가 인덱스에 따라 나타내는 모양이 다를것. 
        function imgSel (index){
            switch(index){
                case 0:     
                 $("div").html('<img src="image/content_facebook.png" alian="bottom">'); //.html로 body부분의 div밑에 표현한다. 주소, 정렬은 bottom으로 <이게의미가 있나?
                 break;
                case 1:     
                 $("div").html('<img src="image/content_google.png" alian="bottom">');
                  break;
                case 2:     
                 $("div").html('<img src="image/content_pinterest.png" alian="bottom">');
                 break;
                case 3:     
                 $("div").html('<img src="image/content_twitter.png" alian="bottom">');
                 break;
                case 4:     
                 $("div").html('<img src="image/content_path.png" alian="bottom">');
                  break;               
            }                
        }
        
 
        //창이 준비되면
        $(document).ready(function(){
            tabMenu("#tabMenu1",imgSel); //tabMenu 함수 (body부분의 tabMenu1을 넘길거고, imgSel을 호출)
        });
 
        function tabMenu(selector,callback){//라이브러리      
          $("li").click(function(){//이벤트, body부분의 태그"li"가 클릭되면
                callback($(this).index()); //li태그의 index를 던져버린다. 
            });
        };
 
        //즉 tabMenu에 들어온 #tabMenu1의(ul태그), 함수 imgSel을 던지고
        // #tabMenu1의 li태그들을 클릭할 때, 
        // callback(= imgSel(li태그의 인덱스))를 실행하겠단 소리.     
        // 그래서 callback으로 인해 imgSel(li태그 인덱스)가 넘어가고
        // li태그 인덱스를 switch로 판별, 
        // 인덱스 별로 div 하위 img 태그를 뿌려준다.
        // attend를 써도 div 하위에 추가가 되지만 버튼을 누를때 마다 객체가 생성 된다
        // 계속 끝없이 추가 되니까 attend보단 html이 맞는듯
    </script>
 
</head>
<body>
        <ul class="tab-menu" id="tabMenu1">
            <li class="menuitem1">google</li>                
            <li class="menuitem2">facebook</li>
            <li class="menuitem3">pinterest</li>
            <li class="menuitem4">twitter</li>
            <li class="menuitem5">path</li>
        </ul>
        <div>
        </div>    
        
    </body>
</html>
반응형