Skip to content

Instantly share code, notes, and snippets.

@VincentHelwig
Created November 5, 2014 11:46

Revisions

  1. VincentHelwig created this gist Nov 5, 2014.
    12 changes: 12 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    // FROM http://jsperf.com/test-offset-jquery-vs-vanilla
    function offset(elt) {
    var rect = elt.getBoundingClientRect(), bodyElt = document.body;

    return {
    top: rect.top + bodyElt .scrollTop,
    left: rect.left + bodyElt .scrollLeft
    }
    }
    var offsetElt = offset(document.getElementById('element'));
    offsetElt.top;
    offsetElt.left;