function inlineSize(el) {
// , ,
var hiddenStyle = "left:-10000px;top:-10000px;height:auto;width:auto;position:absolute;" ;
// box
// inline
var clone = document .createElement( 'div' );
// ,
// .
for ( var i in el.style) {
try {
if ((el.style[i] != '' ) && (el.style[i].indexOf( ":" ) > 0)) {
clone.style[i] = el.style[i];
}
} catch (e) {}
}
// , .
// , IE style
document .all ? clone.style.setAttribute( 'cssText' , hiddenStyle) : clone.setAttribute( 'style' , hiddenStyle);
// . .
clone.innerHTML = el.innerHTML
// .
// , parent, iframe?
parent. document .body.appendChild(clone);
// .
var rect = {width:clone.clientWidth,height:clone.clientHeight};
// ...
parent. document .body.removeChild(clone);
// .
return rect;
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/56814/
All Articles