Created
December 27, 2012 15:05
-
-
Save rainyjune/4388960 to your computer and use it in GitHub Desktop.
Querying the scrollbar positions of a window
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
// Return the current scrollbar offsets as the x and y properties of an object | |
function getScrollOffsets(w) { | |
// Use the specified window or the current window if no argument | |
w = w || window; | |
// This works for all browsers except IE versions 8 and before | |
if (w.pageXOffset != null) return {x: w.pageXOffset, y:w.pageYOffset}; | |
// For IE (or any browser) in Standards mode | |
var d = w.document; | |
if (document.compatMode == "CSS1Compat") return {x:d.documentElement.scrollLeft, y:d.documentElement.scrollTop}; | |
// For browsers in Quirks mode | |
return { x: d.body.scrollLeft, y: d.body.scrollTop }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment