2013-10-08 3 views
1

같은 버튼을 두 번 이상 누르면 다음 슬라이드 효과가 적용됩니다. 의미, 빨간 버튼을 선택하여 색상을 표시하고 빨간색을 다시 누르면 해당 색상을 숨 깁니다. 세 번째로 누르면 누를 수 없습니다. 빨간색이 다시 작동하려면 다른 색상을 선택해야합니다. 이것은 모든 버튼에서 발생합니다. 어떻게 그만합니까? fiddle demo연속 버튼을 누를 때 버튼이 작동하지 않습니다.

// When the DOM is ready, initialize the scripts. 
jQuery(function($){ 

    // Get a reference to the container. 
    var container = $(".container"); 

    // Bind the link to toggle the slide. 
    $("a").click(function(event){ 
     // Prevent the default event. 
     event.preventDefault(); 
     var $this = $(this); 
     var $target = $("#target"); 

     if ($target.attr("class") === $this.attr("data-color")) { 
      container.slideUp(500); 
     } else { 
      // Hide - slide up. 
      container.slideUp(500, function(){ 
       $target.attr("class", $this.attr("data-color")); 
       // Show - slide down. 
       container.slideDown(500); 
      }); 
     } 
    }); 

}); 

답변

1

당신은 다시 아래로 컬러 슬라이드를 한 번 클래스 특성을 제거해야한다, 그렇지 않으면 당신의 상태를 전달합니다

container.slideUp(500, function() { 
    $target.removeAttr("class"); 
}); 

데모 : http://jsfiddle.net/k5L5N/2/

+0

가 너무 좋은, 감사합니다! – need2nobasis

관련 문제