Функция обратного вызова slideToggle - PullRequest
0 голосов
/ 01 октября 2009
// 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");
 }
});
};

Кстати, мое меню аккордеона может быть переписано лучше?

Большое спасибо!

1 Ответ

0 голосов
/ 01 октября 2009
jQuery.fn.equalHeight=function() {
  var maxHeight=0;
  this.each(function(){
    if ($(this).height() > maxHeight) {
      maxHeight = $(this).height();
    }
  });
  return this.each(function() {
    $(this).height(maxHeight);
  });
};

ПРИМЕЧАНИЕ: убедитесь, что это определено, прежде чем вызывать его в своем коде аккордеона:).

Если ничего не помогло, попробуйте этот плагин .

...