Skip to content

Instantly share code, notes, and snippets.

@Rycochet
Created August 15, 2017 11:12
Show Gist options
  • Select an option

  • Save Rycochet/1a9933b7fa51a1139c486a9e2ffc5da8 to your computer and use it in GitHub Desktop.

Select an option

Save Rycochet/1a9933b7fa51a1139c486a9e2ffc5da8 to your computer and use it in GitHub Desktop.

Revisions

  1. Rycochet created this gist Aug 15, 2017.
    21 changes: 21 additions & 0 deletions getHeight.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    /**
    * Get the height of the display, based on body height, then the lowest element within it
    */
    function getHeight(): number {
    var i = 0,
    body = document.body,
    style = body.style,
    elements = document.querySelectorAll("body *"),
    best = body.offsetHeight + (parseInt(style.marginTop, 10) || 0) + (parseInt(style.marginBottom, 10) || 0);;

    while (i < elements.length) {
    let element = elements[i++],
    bottom = element.getBoundingClientRect().bottom + (parseInt(getComputedStyle(element).marginBottom, 10) || 0);

    if (bottom > best) {
    best = bottom;
    }
    }

    return best;
    }