2014-06-18 6 views
0

반응적인 관리 대시 보드를 만들기 위해 부트 스트랩 3을 사용하고 있습니다. 그래서 사이드 바 보이기와 숨기기를위한 버튼을 만들었습니다. 어떻게 든 내 페이지를로드 할 때 내 토글 버튼을 숨기고 토글 이벤트는 전혀 작동하지 않습니다.Jquery Toggle Toggle Toggle Toggle (토글 버튼을 어떻게 든 숨 깁니다.)

HTML (jqueryUI와)

<div class="btn-toggle-sidebar"> 
    <i class="fa fa-bars fa-lg"></i> 
</div> 

<div class="sidebar-left"> 

</div> 


<div class="page-content"> 

</div> 

jQuery를

$(".btn-toggle-sidebar").toggle(function() {   
      $(".sidebar-left").animate({left: -220}, 500); 
      $(".page-content").animate({marginLeft: 0}, 500);      
     }, function() {   
      $(".sidebar-left").animate({left: 0}, 500); 
      $(".page-content").animate({marginLeft: 220}, 500);    
     }); 
+0

'toggle()'은 단지 요소의 가시성을 토글합니다. 아마 대신'click()'을 사용하고 싶을 것이다. – j08691

+0

위 핸들을 준비 핸들러 안에 넣었는지 확인하십시오. $ (document) .ready (function() { // .ready() 핸들러} }) ' – ahgindia

+0

Okey 어떻게해야합니까? 다시 클릭하면 다시 나타납니다. – Julez

답변

0
$(function(){ 
    $(".btn-toggle-sidebar").click(function(){ 
     if ($(this).hasClass("active")){ 
      $(".sidebar-left").animate({left: 0}, 500); 
      $(".page-content").animate({marginLeft: 220}, 500); 
      $(this).removeClass("active"); 
     } else { 
      $(".sidebar-left").animate({left: -220}, 500); 
      $(".page-content").animate({marginLeft: 0}, 500); 
      $(this).addClass("active"); 
     } 
    }); 
}); 

이 당신을 위해 그것을해야한다. (내가 애니메이션을 잘못 잡았을 지 모르지만)