2014-06-18 27 views
0

Im使用Bootstrap 3制作响应式管理仪表板。 所以我创建了一个显示按钮并隐藏侧边栏。 不知何故,当我加载我的网页时,它隐藏了我的切换按钮和切换事件。Jquery Toggle无法正常工作(它隐藏了我的切换按钮)

HTML

<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的(带jQueryUI的)

$(".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

确保你把你的上面的javascript放在准备好的处理程序中'$(document).ready(function(){Handler for .ready()called。 });' – 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"); 
     } 
    }); 
}); 

这应该为你做它。 (虽然我可能错误地获得了动画)