2017-05-03 15:35:00 +02:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
*
|
2017-10-14 18:40:54 +02:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-05-03 15:35:00 +02:00
|
|
|
*
|
|
|
|
* @providesModule getUnboundedScrollPosition
|
|
|
|
* @typechecks
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the scroll position of the supplied element or window.
|
|
|
|
*
|
|
|
|
* The return values are unbounded, unlike `getScrollPosition`. This means they
|
|
|
|
* may be negative or exceed the element boundaries (which is possible using
|
|
|
|
* inertial scrolling).
|
|
|
|
*
|
|
|
|
* @param {DOMWindow|DOMElement} scrollable
|
|
|
|
* @return {object} Map with `x` and `y` keys.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getUnboundedScrollPosition(scrollable) {
|
|
|
|
if (scrollable.Window && scrollable instanceof scrollable.Window) {
|
|
|
|
return {
|
|
|
|
x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
|
|
|
|
y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
x: scrollable.scrollLeft,
|
|
|
|
y: scrollable.scrollTop
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getUnboundedScrollPosition;
|