Last active
August 29, 2015 14:25
-
-
Save aseredenko/d0cf7e12407f7e5ab604 to your computer and use it in GitHub Desktop.
Crossbrowser getting ScrollTop (source: http://stackoverflow.com/questions/871399/cross-browser-method-for-detecting-the-scrolltop-of-the-browser-window)
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 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; | |
} | |
} | |
$(window).scroll( function (){ | |
console.log(getScrollTop()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment