2013-02-21 3 views
0

내 연락처는 두 개의 서로 다른 div를 사용하여 토글합니다. 클래스와 함께 div를 클릭하면이 열려있는 내용을 열고 내용을 닫습니다. 클래스 "닫기"를 사용하여 div를 클릭합니다.여러 div가있는 div 콘텐츠를 전환하는 방법은 무엇입니까?

<div class="open"></div> 
<div class="close"></div> 

<div id="contents"></div> 

어떻게하면됩니까?

$('.open').toggle(function(){ 
    $('#contents').hide(); 
    $('.wrapper').animate({'width':'200px'}).end().find('.content').animate({ 'right': '30px' }) 
}, 
function() { 
    $('#contents').show();  
    $('.wrapper').animate({'width':'40px'}).end().find('.content').animate({ 'right': '0' })  
}); 

감사합니다 :

이 내 스크립트입니다!

+1

토글 이벤트 핸들러는 HTTP 1.9에서 1.8에서 사용되지 않으며 제거 된 그들을 분리하는 별도의 요소에 클릭 이벤트 처리기를 바인딩 할 수 있습니다 : //api.jquery.com/toggle-event/ –

+0

'}, function (.close) {'시도했지만 작동하지 않습니다! –

답변

2

당신은

$('div.open').click(function(){ 
    // your open code here 
}); 
$('div.close').click(function(){ 
    // your close code here 
}); 
1
$(".open").click(function() { 
    $("#contents").show(); 
}); 

$(".close").click(function() { 
    $("#contents").hide(); 
}); 
2

2 개 클릭 기능

$('.close').click(function(){ 
    $('#contents').hide(); 
    $('.wrapper').animate({'width':'200px'}).end().find('.content').animate({ 'right': '30px' }) 
}); 
$('.open').click(function() { 
    $('#contents').show();  
    $('.wrapper').animate({'width':'40px'}).end().find('.content').animate({ 'right': '0' })  
}); 
관련 문제