제이쿼리 소스 보는데 궁금해서 질문드립니다....ㅠ.ㅜ; > 자유게시판

자유게시판

제이쿼리 소스 보는데 궁금해서 질문드립니다....ㅠ.ㅜ; 정보

제이쿼리 소스 보는데 궁금해서 질문드립니다....ㅠ.ㅜ;

본문

HTML소스

<div class="all">
     <div class="tabSet">
         <ul class="tabs">
             <li><a href="#panel1-1" class="on">panel 1</a></li>
                <li><a href="#panel1-2" >panel 2 </a></li>
                <li><a href="#panel1-3" >panel 3 </a></li>
                <li><a href="#panel1-4" >panel 4 </a></li>
         </ul>
            <div class="panels">
             <div class="panel" id="panel1-1">This is panel1. This is panel1. This is panel1. This is panel1. This is panel1.</div>
                <div class="panel" id="panel1-2">This is panel2. This is panel2. This is panel2. This is panel2. This is panel2.</div>
                <div class="panel" id="panel1-3">This is panel3. This is panel3. This is panel3. This is panel3. This is panel3.</div>
                <div class="panel" id="panel1-4">This is panel4. This is panel4. This is panel4. This is panel4. This is panel4.</div>
            <!--/panels --></div>
        <!--/tabSet --></div>
       
        <div class="tabSet">
         <ul class="tabs">
             <li><a href="#panel2-1" >panel 1</a></li>
                <li><a href="#panel2-2" >panel 2 </a></li>
                <li><a href="#panel2-3" class="on" >panel 3 </a></li>
                <li><a href="#panel2-4" >panel 4 </a></li>
         </ul>
            <div class="panels">
             <div class="panel" id="panel2-1">This is panel1. This is panel1. This is panel1. This is panel1. This is panel1.</div>
                <div class="panel" id="panel2-2">This is panel2. This is panel2. This is panel2. This is panel2. This is panel2.</div>
                <div class="panel" id="panel2-3">This is panel3. This is panel3. This is panel3. This is panel3. This is panel3.</div>
                <div class="panel" id="panel2-4">This is panel4. This is panel4. This is panel4. This is panel4. This is panel4.</div>
            <!--/panels --></div>
        <!--/tabSet --></div>

    </div>


-----------------------------------------------------------------------
제이쿼리소스

$(function(){
 $('.tabSet').each(function(){
   // 사용할 요소 준비      
   var topDiv = $(this);
   var anchors = topDiv.find('ul.tabs a');
   var panelDivs =  topDiv.find('div.panel');
   // 마지막으로 클릭한 a 요소, 패널을 저장하기 위한 변수를 정의
   var lastAnchor;
   var lastPanel;
   // 탭부분을 표시
   anchors.show();

   //처음부터 열어 둘 패널을 취득
   /*filter메소드란 여러 요소중에 지정한 셀럭터의 요소를 추출하는 메소드-*/
   lastAnchor = anchors.filter('.on');  
   lastPanel = $(lastAnchor.attr('href'));


   //패널을 모두 숨기고 첫 패널만 열기
   panelDivs.hide();
   lastPanel.show();
   //이벤트를 설정
   anchors.click(function(event){
       //a요소 클릭의 디폴트 동작을 무효화
       event.preventDefault();
       //클릭된 a 요소, 해당패널을 취득
       var currentAnchor = $(this);
       var currentPanel = $(currentAnchor.attr('href'));
       
       lastAnchor.removeClass('on');//마지막에 클릭된 탭의 강조표시를 없앰
       currentAnchor.addClass('on');//클릭된 탭을 강조 표시 시킴
       lastPanel.hide();// 마지막에 열린 패널을 숨김
       currentPanel.show();//클린된 탭에 해당하는 패널을 표시
       
       // 다음의 처리를 위해 클릭된 a요소, 패널을 변수에 저장
       lastAnchor = currentAnchor;
       lastPanel = currentPanel;
           });
          });    
     });


-----------------------------------------------------------------------------------------------
위의 소스 중에서
lastAnchor = anchors.filter('.on');
lastPanel = $(lastAnchor.attr('href'));


<-- 저 두개는 몬 차이죠??


lastAnchor 라는 변수에 
anchors.filter('.on'); -> 즉,  class on 에 관한 요소을 넣는거고  
lastPanel 라는 변수에 lastAnchor.attr('href')를; -> href 값을 추출해서 넣는거로 이해를 했는데요

lastPanel = $(lastAnchor.attr('href')); 를 윗줄처럼 lastPanel = lastAnchor.attr('href')로
바꾸면 동작을 안하더라구요...ㅠ.ㅜ;
lastAnchor와 lastPanel 둘 다 변수에 다 일정 값을 넣는 것 같은데요.


자바스크립트도 모르고 제이쿼리도 잘 모르는 디자이너라 간단한거에도 헤메고 있네요...ㅠ.ㅜ;;
아흐 ..플그램은 넘 어렵...ㅠ.ㅜ;







추천
0

댓글 8개

이걸 어찌 설명해야 하나...

lastPanel = lastAnchor.attr('href') 이거 자체는 href 에 대한 "값"을 넣는거구요. 음, 즉 href="http://naver.com" 으로 되어 있으면 lastPanel 에 http://naver.com << 이 주소 값이 들어가는거고

$(lastAnchor.attr('href')) 는 lastPanel 에 해당 href 오브젝트 자체를 넣는다고 봐야 ㅎ.. 하는데, 어 이걸 뭐라고 설명 해야 할지 ㅜㅜㅜ 저도 jQuery 는 깊게 안파고 들어가서 어떻게 개념적으로 설명을 못해 드리겠어요 ; _ ;
소스 다시 찬찬히 봤네요 ㅎㅎ

lastPanel 에는 오브젝트를 삽입 해야 하는데 lastAnchor.attr('href') 게 쓰시면 #panel2-4 (href 값)의 문자열만 들어가겠죠?

하지만 $(lastAnchor.attr('href')) 이렇게 쓰면, lastAnchor.attr('href') 의 값이 들어가면서
결국

$('#panel2-4') 이거랑 같은 뜻이 됩니다 :D 그럼 id=panel2-4 를 가진 div 오브젝트가 lastPanel 에 쏙 하고 들어가는거에요~ ㅎㅎ
lastPanel = lastAnchor.attr('href')
요건 lastPanel = "#panel2-4" <-- 순수 문자로 인식

lastPanel = $(lastAnchor.attr('href'));
요건 lastPanel = (id= panel2-4) <-- id =panel2-4로 인식한다는 거죠?

감사합니다....^^
정확하게는

lastPanel = $(lastAnchor.attr('href'));

==>lastPanel = $('#panel2-4');

요렇게 인식이 되는거여요 :D ㅋㅋㅋ 개념적으로는 오케이
전체 199,608 |RSS
자유게시판 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT