mirror of
https://github.com/twisterarmy/twister-react.git
synced 2025-01-25 22:24:26 +00:00
18 lines
511 B
JavaScript
Executable File
18 lines
511 B
JavaScript
Executable File
'use strict';
|
|
|
|
var invariant = require('react/lib/invariant');
|
|
var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM;
|
|
|
|
/**
|
|
* Returns the current scroll position of the window as { x, y }.
|
|
*/
|
|
function getWindowScrollPosition() {
|
|
invariant(canUseDOM, 'Cannot get current scroll position without a DOM');
|
|
|
|
return {
|
|
x: window.pageXOffset || document.documentElement.scrollLeft,
|
|
y: window.pageYOffset || document.documentElement.scrollTop
|
|
};
|
|
}
|
|
|
|
module.exports = getWindowScrollPosition; |