2012-01-25 5 views
1

버튼을 클릭하면 일부 상자를 표시하거나 숨길 수 있습니다. 잘 작동하지만 처음 상자를 숨기려면 2 번 클릭해야합니다.Jquery UI slideUp 및 slideDown

이 내 JS 코드 :

$(function() { 
    $('.title .hide').showContent(); 
}); 

$.fn.showContent = function() { 
    return this.each(function() { 
     var box = $(this); 
     var content = $(this).parent().next('.content'); 

     box.toggle(function() { 
      content.slideDown(400); 
     }, function() { 
      content.slideUp(400); 
     }); 

    }); 
}; 

그리고 드 HTML

<div class="box"> 
    <div class="title"> 
     Title 
     <span class="hide"></span> 
    </div> 
    <div class="content">Content</div> 
</div> 

이 왜? 누군가 나를 도울 수 있습니까? 여기

그리고

는 데모입니다 : (.. 당신이 아무것도하지를 처음 클릭하면 검은 색 버튼을 클릭,하지만 두 번째 시간은 다음 내용이 붕괴됩니다) http://jsfiddle.net/wq7PF/

+0

HTML을 게시하십시오. – j08691

+0

@ j08691 완료. :) – Maanstraat

+0

@Maanstraat HTML에서 말하는 버튼은 어디에 있습니까? – esqew

답변

2
당신의 기능을 역

box.toggle(function() { 
    content.slideUp(400); 
}, function() { 
    content.slideDown(400); 
}); 
+0

jsfiddle demo http://jsfiddle.net/wq7PF/1/ –

+0

Stuppid 실수, thnx :) – Maanstraat