Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81162 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule getUnboundedScrollPosition
10
* @typechecks
11
*/
12
13
"use strict";
14
15
/**
16
* Gets the scroll position of the supplied element or window.
17
*
18
* The return values are unbounded, unlike `getScrollPosition`. This means they
19
* may be negative or exceed the element boundaries (which is possible using
20
* inertial scrolling).
21
*
22
* @param {DOMWindow|DOMElement} scrollable
23
* @return {object} Map with `x` and `y` keys.
24
*/
25
function getUnboundedScrollPosition(scrollable) {
26
if (scrollable === window) {
27
return {
28
x: window.pageXOffset || document.documentElement.scrollLeft,
29
y: window.pageYOffset || document.documentElement.scrollTop
30
};
31
}
32
return {
33
x: scrollable.scrollLeft,
34
y: scrollable.scrollTop
35
};
36
}
37
38
module.exports = getUnboundedScrollPosition;
39
40