UNPKG

scroll-xy

Version:

Get the current x/y scroll position

27 lines (23 loc) 622 B
'use strict' var window = require('global/window') var document = require('global/document') module.exports = function scrollPosition (element) { if (!element || element === window) { return { x: window.scrollX, y: window.scrollY, maximum: { x: document.documentElement.scrollWidth - window.innerWidth, y: document.documentElement.scrollHeight - window.innerHeight } } } return { x: element.scrollLeft, y: element.scrollTop, maximum: { x: element.scrollWidth - element.offsetWidth, y: element.scrollHeight - element.offsetHeight } } }