1

I have javascript code which calculates the height of container.

Two situations:

Correct Height - When I do a hard refresh at the top of the page.

Incorrect Height - When I do a hard refresh somewhere in the middle of the page.

jQuery

    jQuery( document ).ready(function() {
      if (jQuery('.sidebar').length){
        var $sidebar = jQuery('.sidebar');
        var $container = jQuery('.syllabus-container');
        var $writerContainer = jQuery('.writer-container');
        var sideBottom = parseFloat($sidebar.css('top')) + $sidebar.height();
        var contBottom = $container.offset().top + $container.height();
      }
   });

I don't really have a live example, but basically the problem lies in that last line, where it does $container.height(). Can anyone think of any reason for this?

James Mitchell
  • 2,387
  • 4
  • 29
  • 59
  • 2
    SHould probably be doing onload not ready.... – epascarello Sep 10 '17 at 02:11
  • It's likely that you won't get a consistent height either way because the container may not have it's content when this calculation runs. onload is a better option as @epascarello mentioned. – BrandonW Sep 10 '17 at 02:29
  • https://stackoverflow.com/questions/5182016/what-is-the-difference-between-window-load-and-document-ready – BrandonW Sep 10 '17 at 02:32

1 Answers1

0

It's best to use onload instead of ready. This makes the script wait a little bit longer until everything is loaded in.