Javascript String getHeight(fontSize)

Description

Javascript String getHeight(fontSize)


String.prototype.getHeight = function(fontSize)
{
    var span = document.getElementById("__getheight");
    if (span == null) {
        span = document.createElement("span");
        span.id = "__getheight";
        document.body.appendChild(span);
        span.style.display = "block";
        span.style.visibility = "hidden";
        span.style.whiteSpace = "nowrap";
        span.style.width = 340 + 'px';
    }//w  ww  . j  a v a  2  s.c om
    span.innerText = this;
    span.style.fontSize = fontSize + "px";

    return span.offsetHeight;
}



PreviousNext

Related