Is there outerWidth height equivalent in dart( border, margine, padding inclusive element size) -
i find border, margin , padding inclusive size of element. jquery's outerwidth, outerheight methods equivalent.
currently, i'm using silly code below.
real solution?
edit:
neither code posted, rounded width , height, or marginedge trick. browsers uses precision of double draw elements , there difference of 21px , 20.6px matters.
edit2
getboundingclientrect() seems returns border , padding inclusive size, commented lines involving out , added todouble() avoid int not subclass of double error.
revised code:
rectangle outerrect(htmlelement e,[bool include_margin = false]) { htmlelement c = e.clone(true); c.style ..display = 'absolate' ..top = '-1000000px'; document.body.append(c); var r = c.getboundingclientrect(); //rounding down causes troubles downstream //r.width can return int then, // int cannot assigned double double width = r.width.todouble(); double height = r.height.todouble(); int parse(string s){ if(s == '') return 0; if(s.contains('px')){ var m = new regexp('[0-9]+').firstmatch(s); if(m == null) return 0; return int.parse(m.group(0)); } throw "unexpected string ${s}"; } var s = c.style; if(include_margin) { width += parse(s.marginright); width += parse(s.marginleft); // width += parse(s.paddingleft); // width += parse(s.paddingright); height += parse(s.margintop); height += parse(s.marginbottom); // height += parse(s.paddingbottom); // height += parse(s.paddingtop); // height += parse(s.bordertop); // height += parse(s.borderbottom); // height += parse(s.paddingbottom); // height += parse(s.paddingtop); } r = new rectangle(-1,-1,width,height); c.remove(); return r; }
not sure, isn't marginedge on element gives you?
Comments
Post a Comment