Created
July 6, 2015 16:53
-
-
Save raynimmo/f87f799b0b0b10125b63 to your computer and use it in GitHub Desktop.
getting the browsers scroll position
This file contains 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
function getScrollXY() { | |
var x = 0, y = 0; | |
if( typeof( window.pageYOffset ) == 'number' ) { | |
// Netscape | |
x = window.pageXOffset; | |
y = window.pageYOffset; | |
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { | |
// DOM | |
x = document.body.scrollLeft; | |
y = document.body.scrollTop; | |
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { | |
// IE6 standards compliant mode | |
x = document.documentElement.scrollLeft; | |
y = document.documentElement.scrollTop; | |
} | |
return [x, y]; | |
} | |
/* usage: */ | |
var xy = getScrollXY(); | |
var x = xy[0]; | |
var y = xy[1]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment