Download the X Distribution File.
xWidth(ele[, uW])
// xWidth r8, Copyright 2001-2010 Michael Foster (Cross-Browser.com) // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL function xWidth(e,w) { var css, pl=0, pr=0, bl=0, br=0; if(!(e=xGetElementById(e))) return 0; if (xNum(w)) { if (w<0) w = 0; else w=Math.round(w); } else w=-1; css=xDef(e.style); if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') { w = xClientWidth(); } else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) { if(w>=0) { if (document.compatMode=='CSS1Compat') { pl=xGetComputedStyle(e,'padding-left',1); if (pl !== null) { pr=xGetComputedStyle(e,'padding-right',1); bl=xGetComputedStyle(e,'border-left-width',1); br=xGetComputedStyle(e,'border-right-width',1); } // Should we try this as a last resort? // At this point getComputedStyle and currentStyle do not exist. else if(xDef(e.offsetWidth,e.style.width)){ e.style.width=w+'px'; pl=e.offsetWidth-w; } } w-=(pl+pr+bl+br); if(isNaN(w)||w<0) return; else e.style.width=w+'px'; } w=e.offsetWidth; } else if(css && xDef(e.style.pixelWidth)) { if(w>=0) e.style.pixelWidth=w; w=e.style.pixelWidth; } return w; }
24Nov2010viewtopic.php?id=822: Element has no size with "display:none".
04May2009viewtopic.php?id=529: Discussion and demo on "box model".
xTableHeaderFixed.xWidth = function(e,w) { var pl=0, pr=0, b=0; if (!(e = xGetElementById(e))) return false; if (xNum(w)) { if (w < 0) w = 0; // return false ??? else w = Math.round(w); } else w = -1; if (xDef(e.style, e.offsetWidth, e.clientWidth)) { if (w >= 0) { if (document.compatMode=='CSS1Compat') { pl = xGetComputedStyle(e, 'padding-left', 1); pr = xGetComputedStyle(e, 'padding-right', 1); b = e.offsetWidth - e.clientWidth; if (window.opera && e.tagName.toLowerCase() != 'table') { b = Math.round(b / 2); // possibly only for TDs and THs !!! haven't yet finished testing in Opera !!! } w -= (pl + pr + b); if (isNaN(w) || w < 0) return false; } e.style.width = w + 'px'; } w = e.offsetWidth; } else { return false; } return w; };
By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.
Forum support is available at the X Library Support Forums.
Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.
If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.