Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 1.25 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jQuery not resetting nav element width based upon total li width
  2. $(document).ready(function(){
  3.             var wNav = $("#navigation").outerWidth();
  4.             var wLiTotal = 0;
  5.  
  6.             $("#navigation>ul>li").each(function(){
  7.                 wLiTotal += $(this).outerWidth();
  8.                 if((wLiTotal > wNav)||(wLiTotal < wNav)){
  9.                  wNav = wLiTotal +3;
  10.              };
  11.           });    
  12.        });
  13.        
  14. $(document).ready(function() {
  15.     var wNav = $("#navigation").outerWidth();
  16.     var wLiTotal = 0;
  17.  
  18.     $("#navigation>ul>li").each(function() {
  19.         wLiTotal += $(this).outerWidth();
  20.         if ((wLiTotal > wNav) || (wLiTotal < wNav)) {
  21.             wNav += wLiTotal + 3;  // you've increase wNav with its previous value
  22.         };
  23.     });
  24.     $("#navigation").width(wNav); // set new wNav as new width
  25. });
  26.        
  27. $(document).ready(function(){
  28.             var wNav = $("#navigation").outerWidth();
  29.             var wLiTotal = 0;
  30.  
  31.             $("#navigation>ul>li").each(function(){
  32.                 wLiTotal += $(this).outerWidth();
  33.                 if((wLiTotal > wNav)||(wLiTotal < wNav)){
  34.                  wNav = wLiTotal +3;
  35.              };
  36.  
  37.             //setting outer width
  38.             $("#navigation").outerWidth(wNav);
  39.           });    
  40.        });