Skip to content

Instantly share code, notes, and snippets.

@zhuzhuaicoding
Created October 17, 2012 09:04
Show Gist options
  • Select an option

  • Save zhuzhuaicoding/3904600 to your computer and use it in GitHub Desktop.

Select an option

Save zhuzhuaicoding/3904600 to your computer and use it in GitHub Desktop.
scrollTop compatitable way
function getScrollTop(){
var position = [0, 0];
if (typeof window.pageYOffset != 'undefined') {
position = [
window.pageXOffset, window.pageYOffset];
} else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
position = [
document.documentElement.scrollLeft, document.documentElement.scrollTop];
} else if (typeof document.body.scrollTop != 'undefined') {
position = [
document.body.scrollLeft, document.body.scrollTop];
}
return position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment