Better `getUnboundedScrollPosition` for windows
Instead of using browser sniffing, `getUnboundedScrollPosition` can do better and not have to depend on the `getDocumentScrollElement` module.
This commit is contained in:
parent
a4f8ad1bb0
commit
0dc011c40c
|
@ -1,27 +0,0 @@
|
|||
/**
|
||||
* @providesModule getDocumentScrollElement
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
// TODO: Replace this with a UserAgent module.
|
||||
var isWebkit = navigator.userAgent.indexOf('AppleWebKit') > -1;
|
||||
|
||||
/**
|
||||
* Gets the element with the document scroll properties such as `scrollLeft` and
|
||||
* `scrollHeight`. This may differ across different browsers.
|
||||
*
|
||||
* NOTE: The return value can be null if the DOM is not yet ready.
|
||||
*
|
||||
* @param {?DOMDocument} doc Defaults to current document.
|
||||
* @return {?DOMElement}
|
||||
*/
|
||||
function getDocumentScrollElement(doc) {
|
||||
doc = doc || document;
|
||||
return !isWebkit && doc.compatMode === 'CSS1Compat' ?
|
||||
doc.documentElement :
|
||||
doc.body;
|
||||
}
|
||||
|
||||
module.exports = getDocumentScrollElement;
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var getDocumentScrollElement = require('getDocumentScrollElement');
|
||||
|
||||
/**
|
||||
* Gets the scroll position of the supplied element or window.
|
||||
*
|
||||
|
@ -19,7 +17,10 @@ var getDocumentScrollElement = require('getDocumentScrollElement');
|
|||
*/
|
||||
function getUnboundedScrollPosition(scrollable) {
|
||||
if (scrollable === window) {
|
||||
return getUnboundedScrollPosition(getDocumentScrollElement());
|
||||
return {
|
||||
x: document.documentElement.scrollLeft || document.body.scrollLeft,
|
||||
y: document.documentElement.scrollTop || document.body.scrollTop
|
||||
};
|
||||
}
|
||||
return {
|
||||
x: scrollable.scrollLeft,
|
||||
|
|
Loading…
Reference in New Issue