2009-10-01 7 views
0
// accordion 
    $("#left-nav .block h2").click(function(){ 
     $(this).next("div").slideToggle("fast", function() { 
      alert("hey"); 
      $("#left-nav, #content, #aside").equalHeight(); 
     }) 
     .siblings("div:visible").slideUp("fast"); 
     $(this).toggleClass("active"); 
     $(this).siblings("h2").removeClass("active"); 
    }); 
    $("#left-nav .block h3").toggle(function(){ 
     $(this).next("ul").slideToggle("fast"); 
     $(this).removeClass("active"); 
    }, function() { 
     $(this).next("ul").slideToggle("fast"); 
     $(this).toggleClass("active"); 
     $(this).siblings("h3").removeClass("active"); 
    }); 

경고는 작동하지만 열의 크기는 조정되지 않습니다. 다음은 equalHeight 함수입니다.slideToggle 콜백 함수

jQuery.fn.equalHeight=function() { 
var maxHeight=0; 
this.each(function(){ 
if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;} 
}); 
this.each(function(){ 
$(this).height(maxHeight + "px"); 
if (this.offsetHeight>maxHeight) { 
    $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px"); 
} 
}); 
}; 

현재 아도비니즘 메뉴를 더 잘 재 작성할 수 있습니까?

많은 감사!

+1

콜백에 경고가 걸려 있는지 확인해 보았습니까? 만약 그렇다면 우리가하는 코드는 당신의 equalHeight 함수에있다. – Colin

+0

경고가 작동하지만 등 높이 기능이 작동하지 않습니다. – 3zzy

답변

0
jQuery.fn.equalHeight=function() { 
    var maxHeight=0; 
    this.each(function(){ 
    if ($(this).height() > maxHeight) { 
     maxHeight = $(this).height(); 
    } 
    }); 
    return this.each(function() { 
    $(this).height(maxHeight); 
    }); 
}; 

참고 : 아코디언 코드에서 호출하기 전에 정의되어 있는지 확인하십시오. :).

그 밖의 모든 방법이 실패 할 경우 plugin을 사용해보십시오.

+0

작동하지 않습니다. 등가 함수에 문제가 있습니까? – 3zzy

+1

equalHeight 오류가 발생하는 경우 함수를 정의하기 전에 호출했기 때문에 equalHeight 오류가 발생합니다. – Colin