Created
October 10, 2022 00:30
-
-
Save luislobo14rap/961ee82c0983a5ebb3e3c1df460e7df7 to your computer and use it in GitHub Desktop.
getScrolls.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getScrolls.js v1 | |
const getScrolls = { | |
element: window, | |
x: 'scrollX', | |
y: 'scrollY' | |
}; | |
if (!('scrollX' in window && 'scrollY' in window)) { | |
if ('pageXOffset' in window && 'pageYOffset' in window) { | |
getScrolls.x = 'pageXOffset'; | |
getScrolls.y = 'pageYOffset'; | |
} else if (document.documentElement.clientHeight != 0) { | |
getScrolls.element = document.documentElement; | |
getScrolls.x = 'scrollLeft'; | |
getScrolls.y = 'scrollTop'; | |
} else { | |
getScrolls.element = document.body; | |
getScrolls.x = 'scrollLeft'; | |
getScrolls.y = 'scrollTop'; | |
}; | |
}; | |
window.getScrollX = function() { | |
return getScrolls.element[getScrolls.x]; | |
}; | |
window.getScrollY = function() { | |
return getScrolls.element[getScrolls.y]; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getScrolls.min.js v1 | |
window.getScrolls={element:window,x:"scrollX",y:"scrollY"};"scrollX"in window&&"scrollY"in window||("pageXOffset"in window&&"pageYOffset"in window?(getScrolls.x="pageXOffset",getScrolls.y="pageYOffset"):"documentElement"in document||"parentNode"in document.body?(getScrolls.element=document.documentElement||document.body.parentNode,getScrolls.x="scrollLeft",getScrolls.y="scrollTop"):(getScrolls.element=document.body,getScrolls.x="scrollLeft",getScrolls.y="scrollTop"));window.getScrollX=function(){return getScrolls.element[getScrolls.x]},window.getScrollY=function(){return getScrolls.element[getScrolls.y]}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment