2014-10-02 2 views
0

클릭하면 컨테이너를 뒤집기 위해 CSS를 사용하고 있습니다.두 번째 클릭시 컨테이너 표시

페이지의 컨테이너 once flippedhide all other 컨테이너의 뒷면이 확대되도록 JQuery를 얻으려고합니다.

컨테이너가 clicked again 인 경우 return to normal (모든 컨테이너를 다시 표시)로 설정합니다.

이것은 내 코드에 관한 것입니다.

$('.f1_container').click(function(event) { 
    $('.f1_container').toggleClass('active').width(320).height(400);}).click(function(){ 
    $('.f2_container,.f3_container,.f4_container,.f5_container,.f6_container').hide(); 
    }); 

내 숨겨진 컨테이너를 숨긴 채 두 번째 클릭하면 내 문제가 발생합니다.

여기 내 입니다.입니다.

<div class="f1_container"> 
    <div class="shadow f1_card"> 
    <div class="front face"> 
     <img src="images/y1.jpg" style="height: 160px; width: 160px;"> 
    </div> 
    <div class="back face center"> 
     Some text inside here 
    </div> 
    </div><!-- end of shadow f1_card --> 
</div><!-- end of f1_container --> 

<div class="f2_container"> 
    <div class="shadow f2_card"> 
    <div class="front face"> 
     <img src="images/o1a.jpg" style="height: 160px; width: 160px;"> 
    </div> 
    <div class="back face center"> 
     Some text inside here 
    </div> 
    </div><!-- end of shadow f2_card --> 
</div><!-- end of f2_container --> 

<div class="f3_container"> 
    <div class="shadow f3_card"> 
    <div class="front face"> 
     <img src="images/o1a.jpg" style="height: 160px; width: 160px;"> 
    </div> 
    <div class="back face center"> 
     Some text inside here 
    </div> 
    </div><!-- end of shadow f3_card --> 
</div><!-- end of f3_container --> 
+0

사용 .toggle을()? (http://api.jquery.com/toggle/) – nicolas

+2

귀하의 HTML 코드도 제공하십시오. 그렇지 않으면 귀하가 무엇을하려고하는지, 그리고 요소/클래스가 어떻게 호출되고 구조화되어 있는지 이해하기가 매우 어렵습니다. 여기에 실수를 저질렀다면 도움이 될 것입니다 ... – Steini

+0

[피들] (http://jsfiddle.net/wrektshy/)을보고 어떻게 할 수 있는지보십시오. – Regent

답변

3

당신이 정말로이 기능은 특정 각각에 대해 서로 다른 처리기의 톤을하지 않고 모든 컨테이너에 작업 할 것을 가정 할 때, 우리는 jQuery의 attribute ends with selector ($)를 사용할 수 있습니다. _container으로 끝나는 모든 수업과 비교할 수 있습니다. 또한 우리가 클릭 한 컨테이너의 가시성을 토글하지 않도록하기 위해 .not을 사용합니다. 당신의 CSS의 헛소리에

$('*[class$="_container"]').click(function(){ 
    $(this).toggleClass('active'); 
    $('*[class$="_container"]').not(this).toggle(); 
}); 

, 활성 클래스를 확인 너비/높이 제약 조건이 포함되어

.active{ 
    width: 320px; 
    height:400px; 
} 
+0

'[class $ = "_ container"]'와 좋은 점이 있지만 두 번째 클릭시 클릭 된 요소 크기가 다시 정상 크기로 돌아 가지 않습니다. 또한 단순화 할 곳이 있습니다 : $ ('[class $ = "_ container"]')'and'.not (this)'. – Regent

+1

내 [업데이트 된 바이올렛] (http://jsfiddle.net/wrektshy/1/). – Regent

+0

@Regent Yea, 폭/높이가 CSS로 정의되어 있어야합니다. 복사 파스타로 빠르게 이동했습니다. :) – Ohgodwhy

관련 문제