UNPKG

axe-core

Version:

Accessibility engine for automated Web UI testing

34 lines (29 loc) 860 B
/* global dom */ /*eslint complexity: ["error", 14]*/ /** * Get the scroll offset of the document passed in * @method getScrollOffset * @memberof axe.commons.dom * @instance * @param {Document} element The element to evaluate, defaults to document * @return {Object} Contains the attributes `x` and `y` which contain the scroll offsets */ dom.getScrollOffset = function (element) { 'use strict'; if (!element.nodeType && element.document) { element = element.document; } // 9 === Node.DOCUMENT_NODE if (element.nodeType === 9) { var docElement = element.documentElement, body = element.body; return { left: (docElement && docElement.scrollLeft || body && body.scrollLeft || 0), top: (docElement && docElement.scrollTop || body && body.scrollTop || 0) }; } return { left: element.scrollLeft, top: element.scrollTop }; };