Created
January 21, 2014 08:28
-
-
Save SteAllan/8536274 to your computer and use it in GitHub Desktop.
A cross-browser JS function to get the viewport's scroll top value (http://stackoverflow.com/questions/871399/cross-browser-method-for-detecting-the-scrolltop-of-the-browser-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
function getScrollTop(){ | |
if(typeof pageYOffset!= 'undefined'){ | |
//most browsers except IE before #9 | |
return pageYOffset; | |
} | |
else{ | |
var B= document.body; //IE 'quirks' | |
var D= document.documentElement; //IE with doctype | |
D= (D.clientHeight)? D: B; | |
return D.scrollTop; | |
} | |
} | |
alert(getScrollTop()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment