slideToggle回调函数

时间:2009-10-01 02:52:48

标签: jquery slidetoggle

// 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 :(得分: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