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 関数です。

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");
 }
});
};

ところで、私のアコーディオンメニューをもっとうまく書き直すことはできますか?

どうもありがとう!

4

1 に答える 1

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);
  });
};

注:アコーディオンコードで呼び出す前に、これが定義されていることを確認してください:)。

他のすべてが失敗した場合は、このプラグインを試してください。

于 2009-10-01T03:29:28.257 に答える