Skip to content

Instantly share code, notes, and snippets.

@soerson
Created July 1, 2016 04:18
Show Gist options
  • Select an option

  • Save soerson/0c492bcc23c82bfa77becaf739421249 to your computer and use it in GitHub Desktop.

Select an option

Save soerson/0c492bcc23c82bfa77becaf739421249 to your computer and use it in GitHub Desktop.
getPageScroll.js
var getPageScroll = (window.pageXOffset !== undefined) ?
function () {
return {
top: pageYOffset,
left: pageXOffset
}
} : function () {
var html = document.documentElement;
var body = document.body;
var top = html.scrollTop || body && body.scrollTop || 0;
top -= html.clientTop; // only for IE7
var left = html.scrollLeft || body && body.scrollLeft || 0;
left -= html.clientLeft; // only for IE7
return {
top: top,
left: left
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment