My goal is to dynamically hide a navigation menu if there isn't enough space in the window. The navigation menu is within a wrapper that also includes a logo, and I use the following code to determine if there is sufficient room:
if ($(window).width() < ($('#logo').outerWidth() + $('#nav').outerWidth()))
$('#nav').hide();
I have this function running when the document loads and whenever the window is resized. However, I noticed an issue where if the window was initially too small, the navigation menu wasn't being hidden. Upon further investigation, I discovered that the width of the nav element was incorrectly calculated when the document first loaded.
The navigation menu contains list items (li) and their widths are consistently 3-4px smaller than expected during the initial calculation, but they adjust properly upon resizing the window. Can anyone shed light on why this discrepancy might be occurring?