简体   繁体   中英

Getting new height after accordion has expanded

JQuery Accordion

(function(jQuery){
     jQuery.fn.extend({  
         accordion: function() {
            return this.each(function() {

                var $ul = $(this);

                if($ul.data('accordiated'))
                    return false;

                $.each($ul.find('ul'), function(){
                    $(this).data('accordiated', true);
                    $(this).hide();
                });

                $.each($ul.find('a'), function(){
                    $(this).click(function(e){
                        //if(!$(this).hasClass('Active')) {
                            activate(this);
                            return void(0);
                        //}
                    });
                });

                var active = $('.Active');

                if(active){
                    activate(active, 'toggle');
                    $(active).parents().show();
                }

                function activate(el,effect){
                    if (!effect) {
                      $(el)
                       .toggleClass('Active')
                       .parent('li')
                       .siblings()
                       .find('a')
                       .removeClass('Active')
                       .parent('li')
                       .children('ul')
                       .slideUp('fast');
                    }
                  $(el)
                  .siblings('ul')[(effect || 'slideToggle')]((!effect)?'fast':null);
                }

            });
        } 
    }); 
})(jQuery);

Calling Accordion

$('.Menu.Open').accordion();

The Problem

.Menu.Open is inside of .SideNav of which I want to get the new height after my accordion has collapsed/expanded content to set the height of .Main

I've been looking into timers and timed events however I just cannot get this to work after my accordion has expanded and feel my attempts are completely wrong, I'd hate to flood this page with them all!

Looking at your code, you are relying on Jquery.slideUp/slideDown to expand/collapse your accordion. If I understood you correctly you are trying to measure height after the animation is complete. I believe this is what you are looking for

$('element').slideUp('fast', function(){ perform_measurement_here();});

Also, for your reference

http://api.jquery.com/slideup/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM