Marco M. Jaeger
2006-Jul-31 14:43 UTC
how to get border, padding, and margin of a given element
Hello, I was wondering what the best way would be to get border, padding, and margin of a given element, regardless how they were defined in the stylesheet - please see what I have so far: What happens, if the border is not set like this for instance: border-left-width but like this: border: 10px solid.. _getOffsetDim: function(el) { if (!$(el)) return false; var oDim = [] oDim[''width''] = ( parseInt(el.getStyle(''border-left-width'')) + parseInt(el.getStyle(''border-right-width'')) + parseInt(el.getStyle(''padding-left'')) + parseInt(el.getStyle(''padding-right'')) + parseInt(el.getStyle(''margin-left'')) + parseInt(el.getStyle(''margin-right'')) ); oDim[''height''] = ( parseInt(el.getStyle(''border-top-width'')) + parseInt(el.getStyle(''border-bottom-width'')) + parseInt(el.getStyle(''padding-top'')) + parseInt(el.getStyle(''padding-bottom'')) + parseInt(el.getStyle(''margin-top'')) + parseInt(el.getStyle(''margin-bottom'')) ); return oDim; }, Thank you in advance for your input. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Thomas Fuchs
2006-Jul-31 14:48 UTC
Re: how to get border, padding, and margin of a given element
Just a reminder: be aware of the fact that stuff like border, padding, margin, etc. take units other than pixels. -Thomas Am 31.07.2006 um 16:43 schrieb Marco M. Jaeger:> > > > > > > Hello, > > I was wondering what the best way would be to get border, padding, > and margin of a given element, regardless how they were defined in > the stylesheet – please see what I have so far: > > > > What happens, if the border is not set like this for instance: > border-left-width but like this: border: 10px solid…. > > > > _getOffsetDim: function(el) { > > if (!$(el)) return false; > > var oDim = [] > > oDim[''width''] = ( > > > > parseInt(el.getStyle(''border-left-width'')) + > > > > parseInt(el.getStyle(''border-right-width'')) + > > > > parseInt(el.getStyle(''padding-left'')) + > > > > parseInt(el.getStyle(''padding-right'')) + > > > > parseInt(el.getStyle(''margin-left'')) + > > > > parseInt(el.getStyle(''margin-right'')) > > > ); > > oDim[''height''] = ( > > > > parseInt(el.getStyle(''border-top-width'')) + > > > > parseInt(el.getStyle(''border-bottom-width'')) + > > > > parseInt(el.getStyle(''padding-top'')) + > > > > parseInt(el.getStyle(''padding-bottom'')) + > > > > parseInt(el.getStyle(''margin-top'')) + > > > > parseInt(el.getStyle(''margin-bottom'')) > > > ); > > > > return oDim; > > > > }, > > > > Thank you in advance for your input. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs-- Thomas Fuchs wollzelle http://www.wollzelle.com questentier on AIM madrobby on irc.freenode.net http://www.fluxiom.com :: online digital asset management http://script.aculo.us :: Web 2.0 JavaScript http://mir.aculo.us :: Where no web developer has gone before _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs