Last active
February 28, 2018 10:06
-
-
Save odil-io/64ea2921402e062468650db7fffc5b8b to your computer and use it in GitHub Desktop.
JS: Vanilla Cross-Browser scroll position reporting
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
//https://stackoverflow.com/a/8028584 | |
function getScrollPercent() { | |
var h = document.documentElement, | |
b = document.body, | |
st = 'scrollTop', | |
sh = 'scrollHeight'; | |
return (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100; | |
} | |
document.addEventListener('scroll', function(){ | |
console.log( getScrollPercent() ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment