Skip to content

Instantly share code, notes, and snippets.

@stekhn
Last active December 28, 2015 09:49
Show Gist options
  • Save stekhn/7481563 to your computer and use it in GitHub Desktop.
Save stekhn/7481563 to your computer and use it in GitHub Desktop.
Function that returns the current scroll position. Useful for "snowfallesk" and parallax scrolling projects.
function getScrollY() {
var currentY = 0;
if (typeof( window.pageYOffset ) == 'number') {
currentY = window.pageYOffset;
} else if (document.body && ( document.body.scrollLeft || document.body.scrollTop )) {
currentY = document.body.scrollTop;
} else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop )) {
currentY = document.documentElement.scrollTop;
}
return currentY;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment