0

I have a offcanvas menu (it has display: none by default).

Inside that menu I have my element (display: block) and I want to get the height of this element on page load.

var myElementHeight = $(myElement).outerHeight();

Of course above code returns 0.

Chrome Developer Tools:

Menu closed:

enter image description here

Menu opened:

enter image description here

One idea comes to my mind: clone this element, append to HTML, hide using visibility property and get the height of this element, but I think it is too tricky.

max
  • 8,632
  • 3
  • 21
  • 55

1 Answers1

2
  $(document).ready(function() {
    $('.element').show();
    _height = $('.element').height();
    $('.element').hide();
  });

Use a loading gif icon if it needs to.

Viktor Maksimov
  • 1,465
  • 1
  • 10
  • 11