qunit/phantom_screenshot.js
function getOffset(selector) {
      var rect, doc, docElem;
      var elem = document.querySelector(selector);

      if(!elem) { return false; }
      if(!elem.getClientRects().length) {
        return { top: 0, left: 0, width: 0, height: 0};
      }

      rect = elem.getBoundingClientRect();

      if(rect.width || rect.height) {
        doc = elem.ownerDocument;
        docElem = doc.documentElement;
      }

      return {
        top: rect.top + window.pageYOffset - docElem.clientTop,
        left: rect.left + window.pageXOffset - docElem.clientLeft,
        width: elem.offsetWidth,
        height: elem.offsetHeight
      }
    }
function getOffset(selector) {
      var rect, doc, docElem;
      var elem = document.querySelector(selector);

      if(!elem) { return false; }
      if(!elem.getClientRects().length) {
        return { top: 0, left: 0, width: 0, height: 0};
      }

      rect = elem.getBoundingClientRect();

      if(rect.width || rect.height) {
        doc = elem.ownerDocument;
        docElem = doc.documentElement;
      }

      return {
        top: rect.top + window.pageYOffset - docElem.clientTop,
        left: rect.left + window.pageXOffset - docElem.clientLeft,
        width: elem.offsetWidth,
        height: elem.offsetHeight
      }
    }
function getOffset ( selector ) { var rect , doc , docElem ; var elem = document . querySelector ( selector ) ; if ( ! elem ) { return false ; } if ( ! elem . getClientRects ( ) . length ) { return { top : 0 , left : 0 , width : 0 , height : 0 } ; } rect = elem . getBoundingClientRect ( ) ; if ( rect . width || rect . height ) { doc = elem . ownerDocument ; docElem = doc . documentElement ; } return { top : rect . top + window . pageYOffset - docElem . clientTop , left : rect . left + window . pageXOffset - docElem . clientLeft , width : elem . offsetWidth , height : elem . offsetHeight } }
Get offset information with native methods
Because not everyone uses jQuery and QUnit does not depend on jQuery
@param  {String} selector (.test, #test)
@return {Object} position of the selector dom
Get offset information with native methods Because not everyone uses jQuery and QUnit does not depend on jQuery